tutorial guide for developer develop dev desarrollador objective-c ios cocoa-touch uiscrollview uitouch

objective c - guide - UIScrollview obteniendo eventos táctiles



ios frameworks (3)

¿Cómo puedo detectar puntos de contacto en mi UIScrollView ? Los métodos delegados toques no están funcionando.


Configurar un reconocedor de gestos táctiles:

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)]; [scrollView addGestureRecognizer:singleTap];

y obtendrás los toques en:

- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture { CGPoint touchPoint=[gesture locationInView:scrollView]; }


Puede crear su propia subclase UIScrollview y luego puede implementar lo siguiente:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"DEBUG: Touches began" ); UITouch *touch = [[event allTouches] anyObject]; [super touchesBegan:touches withEvent:event]; } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"DEBUG: Touches cancelled"); // Will be called if something happens - like the phone rings UITouch *touch = [[event allTouches] anyObject]; [super touchesCancelled:touches withEvent:event]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"DEBUG: Touches moved" ); UITouch *touch = [[event allTouches] anyObject]; [super touchesMoved:touches withEvent:event]; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"DEBUG: Touches ending" ); //Get all the touches. NSSet *allTouches = [event allTouches]; //Number of touches on the screen switch ([allTouches count]) { case 1: { //Get the first touch. UITouch *touch = [[allTouches allObjects] objectAtIndex:0]; switch([touch tapCount]) { case 1://Single tap break; case 2://Double tap. break; } } break; } [super touchesEnded:touches withEvent:event]; }


Si estamos hablando de los puntos dentro de la vista de desplazamiento, entonces puedes enlazar con el método de delegado:

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView

y dentro del método, lea la propiedad:

@property(nonatomic) CGPoint contentOffset

desde scrollView para obtener la coordinación.