Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double-tap or two single-taps?

Tags:

iphone

What is the time limit for two taps to be considered a double-tap, on the iPhone OS?

// Edit: Why is this important?

In order to handle single-tap and double-tap differently, Apple's guide says to do performSelector...afterDelay with some 'reasonable' interval on first tap (and cancel it later if the second tap is detected).

The problem is that if the interval is too short (0.1), the single tap action will be performed even when double-tapping (if relying only on tapCount, that is). If it's too long (0.8), the user will be waiting unnecessarily for the single-tap to be recognized, when there is no possibility for a double-tap.

It has to be exactly the correct number, in order to work optimally, but definitely not smaller, or there's a chance for bugs (simultaneous single-tap and double-tap).

like image 217
Jaka Jančar Avatar asked Aug 15 '09 18:08

Jaka Jančar


People also ask

Should you always double tap?

Instruction and practice of the double-tap improves overall accuracy as shooters often do not have the gun fully extended on the first shot meaning the second of a double-tap is usually the better.

What does double tapping do?

“Double tap” is another way to refer to “liking” a post, especially on Instagram, where double tapping an image is the method for “liking” it. Sometimes brands invite followers to “double tap” their post in order to increase engagement.

Where did the term double tap come from?

The term “double tap” became especially popular in general parlance following its usage in the film Zombieland, in which it referred to the practice of ensuring a zombie was dead by shooting or striking its head a second time.

What does double tap do on iPhone?

You can double-tap or triple-tap the back of iPhone to perform actions such as taking a screenshot, turning on an accessibility feature, running a shortcut, and more. Go to Settings > Accessibility > Touch > Back Tap. Choose Double Tap or Triple Tap, then choose an action.


1 Answers

You can detect any number of tap by the tap gesture. No need of playing with NSTouches either. For all the user seeking for the solution here it is.

These simple lines of code does the duty of single and double tap functionality.

  UITapGestureRecognizer *doubleTapRecg = [[UITapGestureRecognizer alloc]
                                             initWithTarget:self 
                                             action:@selector(doubleTapped:)];
    doubleTapRecg.delegate = self;
    doubleTapRecg.numberOfTapsRequired = 2;
    doubleTapRecg.numberOfTouchesRequired = 1;
    [view addGestureRecognizer:doubleTapRecg];


    UITapGestureRecognizer *tapRecg = [[UITapGestureRecognizer alloc]
                                       initWithTarget:self 
                                       action:@selector(tapped:)];
    tapRecg.delegate = self;
    tapRecg.numberOfTapsRequired = 1;
    tapRecg.numberOfTouchesRequired = 1;
    [view addGestureRecognizer:tapRecg];
    [tapRecg requireGestureRecognizerToFail:doubleTapRecg];


    [doubleTapRecg release];
    [tapRecg release];
like image 199
yunas Avatar answered Nov 13 '22 05:11

yunas