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 *