Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Multiple Tap gesture recognizers

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?

like image 294
Satyam Avatar asked Dec 13 '12 19:12

Satyam


1 Answers

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.

like image 178
iDev Avatar answered Sep 20 '22 10:09

iDev