How to detect single/double/triple taps in iPhone ?

By | April 30, 2011

Hi,
How can you detect single/double/triple taps in iPhone using Objective C?
Use the following code to detect single or multiple taps in iPhone/iPad/iPod.
The code can also be used with Cocos2D & Box2D.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
 
    UITouch *urtouch = [touches anyObject];
 
    NSUInteger urtapCount = [urtouch tapCount];
 
    switch (urtapCount) {
 
       case 1:
         NSLog(@"Single Tap Detected!");
          break;
 
       case 2:
          NSLog(@"Double Tap Detected!");
          break;
 
       case 3:
        NSLog(@"Triple Tap Detected!");
        break;
 
      default :
       break;
 
   }
}

Try it out! You can even detect Quadrup!
๐Ÿ™‚

One thought on โ€œHow to detect single/double/triple taps in iPhone ?โ€

  1. Vlad

    Hi,
    In this case you will get all 3 entries in the log for tripple click.
    Need a better solution ๐Ÿ™‚

    Thanks,
    Vlad

    Reply โ†“

Leave a Reply

Your email address will not be published. Required fields are marked *