estoy triyng para hacer un reconocedor de gestos para un simple UIView:¿No se ha agregado UITapGestureRecognizer a un UIView?
UIView *theView = [[UIView alloc] initWithFrame:rect];
[theView setUserInteractionEnabled:YES];
UITapGestureRecognizer *tap = [[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleTap)] autorelease];
[theView addGestureRecognizer:tap];
Si puedo depurar los gestureRecognizers propiedad de la vista que muestra el objeto gesto reconocedor. Pero cuando toco dentro de la vista, no funciona.
El mismo código usando un UIImageView funciona perfecto, ¿alguna idea de por qué no funciona en UIView?
ACTUALIZADO:
Una clase de ejemplo.
@implementation ExampleClass
- (UIView *)getViewInRect:(CGRect)rect
{
UIView *theView = [[UIView alloc] initWithRect:rect];
[theView setUserInteractionEnabled:YES];
UITapGestureRecognizer *tap = [[[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleTap)]
autorelease];
[aText addGestureRecognizer:tap];
return theView;
}
- (UIImageView *)getImageViewInRect:(CGRect)rect
{
UIImageView *theView = [[UIImageView alloc] initWithRect:rect];
[theView setUserInteractionEnabled:YES];
UITapGestureRecognizer *tap = [[[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleTap)]
autorelease];
[theView addGestureRecognizer:tap];
return [theView autorelease];
}
- (void)handleTap
{
NSLog(@"Tap Handled!!", nil);
}
@end
Actualización 2:
Adición UITapGestureRecognizer a todos subvistas de theview no se soluciona el problema ...
FIX IT !!!
OK !! ¡El problema era el CGRect para theView, tenía el ancho establecido en 0.0!
¿Cómo es su función handleTap? ¿Está utilizando un gestureRecognizer en la Superview de theView, que podría captar el gesto? – Seega
handleTap es un método de la misma clase donde vive el código anterior. Desde esta primicia puedo llamarlo sin problemas con [self handleTap]. –
¿Está diciendo que si reemplazó 'UIView' con' UIImageview' en el fragmento de código anterior, funciona? – freespace