Search code examples
iosuitapgesturerecognizer

iOS distinguish single tap and double tap at first opening


I know that I can use requireGestureRecognizerToFail function to distinguish single tap and double tap, but I meet a tiny problem, and I want to fix it. My code is as below:

- (IBAction)singleTap:(UITapGestureRecognizer *)sender {
    NSLOGD_METADATAONLY();
    hideNavigationBar();
    hideStatusBar();
    [sender requireGestureRecognizerToFail:self.doubleTapRecognizer];
}

- (IBAction)doubleTap:(UITapGestureRecognizer *)sender {
    NSLOGD_METADATAONLY();
    //TODO
}

When I open a file and double tap(action1), single tap(result1) will be called firstly and then double tap(result2) will be called.

But if I open a file and single tap(action3), then double tap(action4), the result of action4 is working well,single tap will not be called only double tap will be called. I guess it is because in action3 the function requireGestureRecognizerToFail is called.

My question is HOW CAN I make action1 just call result2 and not call result1?


Solution

  • Write the below lines in ViewDidLoad
    [singleTap requireGestureRecognizerToFail:doubleTap];