Puedo obtener el controlador UIPinchGestureRecognizer
para trabajar con el escalado de un objeto, pero no quiero escalar Quiero cambiar el tamaño. Por ejemplo, tengo un UITextView
y le he adjuntado un gesto UIPinchGestureRecognizer
y si el usuario pellizca quiero cambiar el ancho de la vista de texto para que coincida con el pellizco. No quiero escalarlo para que el UITextView
sea más grande (zoom).¿Cómo puedo utilizar el zoom de pellizco (UIPinchGestureRecognizer) para cambiar el ancho de una UITextView?
Respuesta
Creo que lo que quiere hacer es simplemente multiplicando el ancho del marco de su Textview con la escala del reconocedor gesto:
CGFloat scale = gestureRecognizer.scale;
CGRect newFrame = textView.frame;
newFrame.size = CGSizeMake(scale*newFrame.size.width, newFrame.size.height);
textView.frame = newFrame;
O no es esto lo que quiere decir?
Eso no parece funcionar. El uitextview crece muy rápido y se retrasa. La escala puede ser de 0-20 + –
Impar ... No me esperaba eso. Nunca he usado reconocedores de gestos ... –
¿por qué no eliminar esta respuesta? –
Estoy haciendo exactamente lo mismo. Actualizaré esta publicación si encuentro cómo hacerlo.
Prueba de esto, que funcione para mí (por 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;
}
Lo que realmente me ayudó es _view.bounds = CGRectApplyAffineTransform (initialBounds, zt); Me preguntaba por horas por qué mi tamaño consolidado no cambió ... ¡Muchas gracias! – Oritm
muchos errores en este código. – user2083364
siempre se cuelga al ejecutar este código ... – HoangNA
Tengo cuatro rutinas que tienen que ver con el pinzamiento de un campo de texto. El reconocedor de gestos es la rutina central. Ve si los campos de texto seleccionados van a ser pellizcados fuera de la pantalla, no quiero eso. Si no lo son, entonces le digo que se pellizque con la escala del gesto. Si hay varios seleccionados, envío una notificación para aquellos que no se desentonarán de la pantalla para pellizcarse.
//--------------------------------------------------------------------------------------------------------
// 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];
}
}
Usted tiene que usar en Swift:
func pinchgsterAction(gesture:UIPinchGestureRecognizer){
if (gesture.state == UIGestureRecognizerState.Changed) {
let scale:CGFloat = gesture.scale
gesture.view.transform = CGAffineTransformScale(gesture.view.transform, scale, scale)
}
}
- 1. Límites de escala en el zoom de pellizco de Android
- 2. Galería de Android con zoom de pellizco
- 3. Biblioteca de gráficos HTML5 que admite el zoom pellizco
- 4. Cómo configurar el zoom/ancho inicial para una vista web
- 5. javascript evento para un móvil pellizco/acción de zoom
- 6. ¿Cómo puedo cambiar el ancho de una lista desplegable JComboBox?
- 7. Cómo cambiar el color de UITextview UIDataDetectorTypeLink?
- 8. ¿Cómo puedo saber cuándo finaliza un gesto de pellizco (UIGestureRecognizer)?
- 9. ¿Cómo respondo a un toque en una Vista de mapa de Android, pero ignoro el zoom de pellizco?
- 10. Cambiar el tamaño de la fuente para llenar UITextView?
- 11. Cómo cambiar el ancho de html.DropDownListFor()
- 12. ¿Puedo cambiar el ancho de un gráfico de líneas?
- 13. ggplot - Cambiar el ancho de línea
- 14. Cómo cambiar el tamaño de fuente de uitextview
- 15. pellizcar el zoom para vista personalizada
- 16. ¿Cómo cambiar el nivel de zoom de Google Maps programáticamente?
- 17. Cambiar el ancho de un UIBarButtonItem
- 18. ¿Cómo puedo cambiar el ancho de una ventana de la consola de Windows?
- 19. ¿Cómo puedo cambiar el tamaño de una imagen sin estirarla?
- 20. ¿Cómo puedo establecer el tamaño de fuente de UITextView?
- 21. Primefaces spinner - Cómo cambiar el ancho
- 22. ¿Cómo puedo controlar el ancho de una etiqueta de etiqueta?
- 23. Cambiar el ancho de una barra de desplazamiento
- 24. Cómo incrustar un enlace en una UITextView para el iphone
- 25. UIPinchGestureRecognizer posición de la vista pellizcada entre los dos dedos
- 26. ¿Cómo puedo cancelar un rebote de zoom UIScrollView?
- 27. ¿Cómo puedo ajustar el ancho de DIV para contenidos
- 28. ¿Cómo habilitar los controles de zoom y pellizcar el zoom en un WebView?
- 29. Cómo deshabilitar el teclado en una UITextView?
- 30. ¿Cómo puedo encontrar el ancho de una imagen usando PHP?
No debe atacar UIPinchGestureRecognizers indefensos: P –
@KennyTM Jaja! Bueno, uno ... –
@Jongsma ¿Por qué no? ¡Podría haberlo pellizcado primero! –