Posso ottenere il gestore UIPinchGestureRecognizer
per lavorare con il ridimensionamento di un oggetto ma non voglio ridimensionarlo. Voglio cambiare la dimensione. Ad esempio, ho uno UITextView
e ho allegato un gesto UIPinchGestureRecognizer
e se l'utente si pizzica, voglio cambiare la larghezza della vista testo in modo che corrisponda al pizzico. Non voglio ridimensionarlo in modo che lo UITextView
sia più grande (zoom).Come posso utilizzare lo zoom pizzico (UIPinchGestureRecognizer) per modificare la larghezza di un UITextView?
risposta
Penso che ciò che si vuole fare è semplicemente moltiplicando la larghezza del telaio della vostra textView con la scala del sistema di riconoscimento gesto:
CGFloat scale = gestureRecognizer.scale;
CGRect newFrame = textView.frame;
newFrame.size = CGSizeMake(scale*newFrame.size.width, newFrame.size.height);
textView.frame = newFrame;
O non è questo che vuoi dire?
Questo non sembra funzionare. La visualizzazione di uitext cresce molto rapidamente e viene ritardata. La scala può essere 0-20 + –
Dispari ... Non me l'aspettavo. Non ho mai usato i riconoscitori di gesti ... –
perché non eliminare questa risposta? –
Sto facendo la stessa cosa. aggiornerò questo post se ho trovato come farlo.
Prova questo, il lavoro per me (per UIView):
- (IBAction)handlePinchGesture:(UIGestureRecognizer *)sender {
static CGRect initialBounds;
UIView *_view = sender.view;
if (sender.state == UIGestureRecognizerStateBegan)
{
initialBounds = _view.bounds;
}
CGFloat factor = [(UIPinchGestureRecognizer *)sender scale];
CGAffineTransform zt = CGAffineTransformScale(CGAffineTransformIdentity, factor, factor);
_view.bounds = CGRectApplyAffineTransform(initialBounds, zt);
return;
}
Ciò che mi ha veramente aiutato è _view.bounds = CGRectApplyAffineTransform (initialBounds, zt); Mi sono chiesto per ore perché le mie dimensioni non sono cambiate .. Grazie mille! – Oritm
un sacco di errori in questo codice. – user2083364
si arresta sempre durante l'esecuzione di questo codice ... – HoangNA
Ho quattro routine che si occupano di pizzicare di un campo di testo. Il riconoscitore di gesti è la routine principale. Vede se i campi di testo selezionati verranno rimossi dallo schermo, non lo voglio. Se non lo sono, allora gli dico di pizzicarsi con la scala del gesto. Se ci sono più selezioni, invio una notifica per coloro che non rimuoveranno lo schermo per pizzicarsi.
//--------------------------------------------------------------------------------------------------------
// pinchElement
// Description: Called to di the element scale, in our case, we are adjusting the length.
//
//--------------------------------------------------------------------------------------------------------
- (void)pinchElement:(CGFloat)scale {
//Grab how big we are now
CGRect textFieldBounds = textField.bounds;
//Multiple the Scale of the Pinch by the Width to get our new width.
CGFloat newWidth = textFieldBounds.size.width * scale;
CGFloat widthChange = newWidth - textFieldBounds.size.width;
CGRect newBounds = CGRectMake(0, 0, newWidth, textFieldBounds.size.height);
[textField setBounds: newBounds];
[textField setCenter: CGPointMake(textField.center.x + widthChange/2, textField.center.y)] ;
[self contentSizeChanged];
}
//--------------------------------------------------------------------------------------------------------
// pinchOffScreen
// Description: Called to see if the Pinch Gesture will cause element to go off screen Gesture
//
//--------------------------------------------------------------------------------------------------------
- (BOOL)pinchOffScreen:(CGFloat)scale {
//Grab how big we are now
CGRect textFieldBounds = textField.bounds;
//Multiple the Scale of the Pinch by the Width to get our new width.
CGFloat newWidth = textFieldBounds.size.width * scale;
//Figure out our Change in Width so we can calculate our new Zen Center
CGRect newElementBounds = CGRectMake(0, 0, newWidth+ kElementFrameOffset*2 + kElementContentFrameOffset*2, textFieldBounds.size.height + kElementFrameOffset*2 + kElementContentFrameOffset*2);
//We want to be sure that we dont size beyond our bounds, find our Parent Origin.
CGRect elementBoundsInSuperView = [self convertRect:newElementBounds toView:[self superview]];
CGFloat xPosition = CGRectGetMidX(elementBoundsInSuperView);
CGFloat yPosition = CGRectGetMidY(elementBoundsInSuperView);
BOOL offScreen = [self calcOffEditorFromXposition:xPosition yPosition:yPosition fromBoundsInSuperView:elementBoundsInSuperView];
return offScreen;
}
//--------------------------------------------------------------------------------------------------------
// handlePinchGesture
// Description: Called when we get a Pinch Gesture
// We want to override the default scaling and set the width.
//
//--------------------------------------------------------------------------------------------------------
- (void)handlePinchGesture:(UIPinchGestureRecognizer *)gestureRecognizer {
if (IoUIDebug & IoUIDebugSelectorNames) {
NSLog(@"%@ - %@", INTERFACENAME, NSStringFromSelector(_cmd));
}
// UIView *element = [gestureRecognizer view];
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
//We are resizing, Select ourself
[self selectSelf];
}
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {
NSSet *selectedElements = [[(IoScreenEditorViewController *)UIAppDelegate.ioMainViewController.currentViewController editorContentViewController] selectedElements];
BOOL aSelectedElementOffscreen = FALSE;
for (IoUIScreenElement* element in selectedElements) {
if ([element pinchOffScreen:[gestureRecognizer scale]]) {
aSelectedElementOffscreen = TRUE;
break;
}
}
if (!aSelectedElementOffscreen) {
[self pinchElement:[gestureRecognizer scale]];
// Let others know they are moving if they are selected
// Setup our data for the Notification
NSMutableDictionary *theUserInfo = [[[NSMutableDictionary alloc] initWithCapacity:1] autorelease];
[theUserInfo setObject:self forKey:@"ElementWithGesture"];
NSNumber * scaleAsNumber = [[NSNumber alloc] initWithFloat:[gestureRecognizer scale]];
[theUserInfo setValue:scaleAsNumber forKey:@"GestureScale"];
[theUserInfo setObject:gestureRecognizer forKey:@"TheGestureRecognizer"];
[scaleAsNumber release];
// Post the Group Rotation Notification.
[[NSNotificationCenter defaultCenter] postNotificationName:kNCSEGroupPinchGesture
object:nil
userInfo:theUserInfo];
}
[gestureRecognizer setScale:1];
}
if ([gestureRecognizer state] == UIGestureRecognizerStateEnded) {
}
}
//--------------------------------------------------------------------------------------------------------
// groupHandlePinchGesture:
// Description: For a groupPinch Notification. Move it! within bounds of course
//
//--------------------------------------------------------------------------------------------------------
- (void) groupHandlePinchGesture:(NSNotification*)notification{
if (IoUIDebug & IoUIDebugSelectorNames) {
NSLog(@"%@ - %@", INTERFACENAME, NSStringFromSelector(_cmd));
}
IoUIScreenElement *element = (IoUIScreenElement *) [[notification userInfo] objectForKey:@"ElementWithGesture"];
//UIRotationGestureRecognizer *gestureRecognizer = (UIRotationGestureRecognizer *) [[notification userInfo] objectForKey:@"TheGestureRecognizer"];
NSNumber *scaleAsNumber = [[notification userInfo] valueForKey:@"GestureScale"];
CGFloat scale = [scaleAsNumber floatValue];
if (IOFNOTEQUAL(self, element) & [self isSelected]){
[self pinchElement: scale];
}
}
Devi usare in rapida:
func pinchgsterAction(gesture:UIPinchGestureRecognizer){
if (gesture.state == UIGestureRecognizerState.Changed) {
let scale:CGFloat = gesture.scale
gesture.view.transform = CGAffineTransformScale(gesture.view.transform, scale, scale)
}
}
- 1. Come abilitare lo zoom pizzico nel commutatore di immagini?
- 2. Android GridView pizzico zoom
- 3. Android webview pizzico zoom Problema
- 4. Come implementare lo zoom con pizzico nella libreria Picasso?
- 5. HTML5 Libreria di grafici che supporta lo zoom con pizzico
- 6. Pizzico Zoom in webview [Android]
- 7. evento javascript per un'azione mobile pizzico/zoom
- 8. Zoom pizzico - Ottenere coordinate touch
- 9. Pizzico Zoom su textview android
- 10. Modificare la larghezza di un UIBarButtonItem
- 11. Highstocks - Come modificare lo zoom predefinito
- 12. Come posso abilitare lo zoom su Android?
- 13. Come rispondere a un tocco su Android MapView, ma ignorare lo zoom pizzico?
- 14. Disattiva zoom pizzico nel webkit (o elettrone)
- 15. Zoom pizzico su un'immagine in Xamarin
- 16. Disattiva zoom pizzico Chrome per l'utilizzo nel chiosco
- 17. D3 come modificare la larghezza e la lunghezza SVG
- 18. è questo CoreText? - Pizzico di testo Aviary zoom expand
- 19. Pizzico per zoomare con Osmdroid
- 20. Come si ottiene la scala della finestra dopo lo schiacciamento/lo zoom su un'app di iPhone?
- 21. Modificare la direzione del testo UITextView
- 22. Implementazione di pizzico e zoom su Android SurfaceView
- 23. Come posso cancellare un rimbalzo dello zoom UIScrollView?
- 24. Come abilitare i controlli di zoom e pizzicare lo zoom in una WebView?
- 25. Visualizza l'animazione del controller come lo zoom e lo zoom
- 26. Come posso modificare un UIViewController esistente per consentire lo scorrimento?
- 27. come impostare il punto di ancoraggio per lo zoom con pinch (GMGridView)
- 28. Posso modificare la larghezza del combobox di Solution Configuration nell'IDE?
- 29. Zoom VideoView per riempire la larghezza, mantenendo le proporzioni
- 30. Uso di ScrollViewer per zoom immagine-pizzico, continua a scattare a sinistra sul pan
Non si dovrebbe attaccare UIPinchGestureRecognizers indifese: P –
@KennyTM Haha! Buono ... –
@Jongsma Perché no? Potrebbe averlo pizzicato per primo! –