Question

I have a UIView with a UIScrollView and I want to catch the event touches but I can not. Not goes into any method below. What is the problem?

- (void) touchesEnded: (NSSet *) toca withEvent: (UIEvent *) evento
{
     NSLog (@ "touchesEnded");

}
- (void) touchesBegan: (NSSet *) toca withEvent: (UIEvent *) evento
{

     NSLog (@ "touchesBegan");

}
- (Void) touchesMoved: (NSSet *) toca withEvent: (UIEvent *) evento
{
     NSLog (@ "touchesMoved");
}

Heading ##enter image description here

thank you

Was it helpful?

Solution

you need to use UIGestureRecognizer. You can add it directly in your viewController:

UITapGestureRecognizer *tap =
              [[UITapGestureRecognizer alloc] initWithTarget:myView action:@selector(yourSelector:)];
          [myView addGestureRecognizer:tapp];

Otherwise you can add it directly with the interface boulder: add gesture recognizer

after adding the gesture recognizer you can use it like a normal outlet.

OTHER TIPS

As Benny Dalby told there is a way of making subclass of UIScrollView and can perform your touch event

In your scroll view subclass implementation file you can perform these function

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];


}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];


}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesEnded:touches withEvent:event];


}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesCancelled:touches withEvent:event];
}

UIScrollView is immune to touchesEnded, touchesBegan, touchesMoved etc.That is it prevents these methods from getting called in the ViewControler.

Possibility 1 :

Use UIGestureRecognizerDelegates to implement touch in ScrollView

Possibility 2 :

Create a subclass of UIScrollView class and override the touchesBegan: and other touch methods

Hope it Helps!!!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top