6

In my application, i've to detect single, double and triple taps. So, I'm using UITapGestureRecognizer. I'm using the following code:

    UITapGestureRecognizer *oneTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapGestureOnAnimal:)];
    oneTap.numberOfTapsRequired = 1;

    UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTapGestureOnAnimal:)];
    doubleTap.numberOfTapsRequired = 2;
    [doubleTap requireGestureRecognizerToFail:oneTap];

    UITapGestureRecognizer* tripleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTripleTapGestureOnAnimal:)];
    tripleTap.numberOfTapsRequired = 3;
    [tripleTap requireGestureRecognizerToFail:doubleTap];

    [self addGestureRecognizer:oneTap];
    [self addGestureRecognizer:doubleTap];
    [self addGestureRecognizer:tripleTap];

But the problem is that its always detect single and double taps only. Its not detecting triple tap at all.... can some one point out the mistake that I am doing to detect triple taps?

Bhushan Firake
  • 9,338
  • 5
  • 44
  • 79
Satyam
  • 15,493
  • 31
  • 131
  • 244

2 Answers2

17

Check with this,

[oneTap requireGestureRecognizerToFail:doubleTap];
[oneTap requireGestureRecognizerToFail:tripleTap];
[doubleTap requireGestureRecognizerToFail:tripleTap];

You had switched the taps in the methods and you were not doing the second line above. Ideally one tap should be detected only when double tap and triple tap fails. And double tap should be detected when triple tap fails.

iDev
  • 23,310
  • 7
  • 60
  • 85
  • Still its not detecting triple tap – Satyam Dec 14 '12 at 07:33
  • @Satyamsvv, If you comment out the other two gestureRecognizers, is it working? – iDev Dec 14 '12 at 07:35
  • @Satyamsvv, Any updates? Was it detecting when the other two are not added to self? This should work. If it is not working, the issue is related to something else. – iDev Dec 14 '12 at 08:20
  • No, its still not working. That's the only code written in that class which is a subview of UIImageView. – Satyam Dec 14 '12 at 14:21
  • @Satyamsvv, That's weird. If that is the only gesture, then also it is not detecting? Is there anything else different from the other two gestures? You have removed the other lines before putting the above right? Check this http://stackoverflow.com/questions/9243868/iphone-3-multiple-detections-of-uigesturerecognizer. They are adding 3 tap gestures. – iDev Dec 14 '12 at 18:31
  • Its working perfect..... dont know what's the issue, just reset the simulator and ran the app again.... it started working. – Satyam Dec 15 '12 at 07:02
  • @iDev, is it possible to do this with delegate? – kelin Apr 13 '15 at 07:29
0

Change your 2 requireGestureRecognizerToFail calls to:

[oneTap requireGestureRecognizerToFail:tripleTap];
[oneTap requireGestureRecognizerToFail:doubleTap];
[doubleTap requireGestureRecognizerToFail:tripleTap];  
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
Bruno Domingues
  • 1,017
  • 9
  • 12
  • Still its not detecting triple tap – Satyam Dec 14 '12 at 07:38
  • I created a test project and it worked. Maybe there is something else in your view that is messing with the gestures. Try creating a project with only one view and add the three gestures and you'll see that it's correct. What else is in your view? I can try to help. – Bruno Domingues Dec 14 '12 at 12:19
  • I created a class inherited from UIImageView and handling the taps in that class (as mentioned in the description). – Satyam Dec 14 '12 at 14:22