Using single-tap and double-tap in the same view

If you are going to use two similar gestures in a view, it could cause the problem.
For example, in the following code snippet, I tried to use single tap for changing screen mode while double tap is used to toggle bookmark flag.

    [self.svContent addGestureRecognizer:toggleFavoriteTap]; 
    [self.svContent addGestureRecognizer:toggleFullScreenTap];

But, there’s one problem with this. When you double tap it, single tap also gets an effect. So, every time, I do the double tap, it also changes the screen mode.

To solve this problem, you can use ‘requireGesutreRecognizerToFail:’ method as shown in below code snippet.

    [self.svContent addGestureRecognizer:toggleFavoriteTap]; 
    [toggleFullScreenTap requireGestureRecognizerToFail:toggleFavoriteTap];
    [self.svContent addGestureRecognizer:toggleFullScreenTap];

It will wait double tap happens or end with single tap. toggleFullScreenTap will not happen until double tap failed and if double tap has succeed, toggleFullScreenTap won’t get any chance to get called.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.