Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone - single tap gesture conflicts with double one

I have a view. I wish to define to kinds of tap gestures for it.

So if a user single tap on the view, view will do A; and if a user double tap on the view, it will do B without doing A.

I added two UITapGestureRecognizer to the view. the single tap is with numberOfTapsRequired = 1; and the double tap is with numberOfTapsRequired = 2;

Also I set return NO for

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {      return NO; } 

However, I found that they conflict with each other. I mean, even if I double tap on the view, both A and B will be invoked.

How can I solve this problem?

Thanks

like image 246
Jackson Tale Avatar asked Aug 24 '11 12:08

Jackson Tale


1 Answers

You can work around this by adding the following line of code. This will make sure that the single tap recognizer only fires when the double tap recognizer failed:

    [singleTapRecognizer requireGestureRecognizerToFail:doubleTapRecognizer]; 
like image 103
Markus Müller-Simhofer Avatar answered Sep 21 '22 17:09

Markus Müller-Simhofer