How To Detect Multiple Taps In iPhone?

Detecting multiple taps is very easy to use. If the user triple taps, you get notified three separate times. You get a single-tap, a double tap and finally triple tap. lets see how it is worked.

Step 1: In Xcode, create a new project with view base application template.

Step 2: Next, double click .xib file to open the file in Interface Builder. Once you’re there ,make sure you set the view to accept multiple touches, and then add four Labels to the view from the library. Once you are done, double click each lebel and press the delete key to get rid to any text. Now control drag from the File’s Owner icon to each label , and connect each one to singleLabel, doubleLabel, tripleLabel, and quadrupleLabel, respectively. Now you can save and go back to  Xcode.

Step 3: The four methods do nothing more in this application than set one of the four labels and use performSelector:withObject:afterDelay: to erase that same label after 1.6 seconds. The eraseMe: method erases any text field that is passed into it.


        singleLabel.text = @"Single Tap Detected";
        [self performSelector:@selector(eraseMe:)
         withObject:singleLabel afterDelay:1.6f];

      doubleLabel.text=@"Double Tap Detected";
     [self performSelector:@selector(eraseMe:)
     withObject:doubleLabel afterDelay:1.6f];

    tripleLabel.text=@"Triple Tap Detected";
    [self performSelector:@selector(eraseMe:)
     withObject:tripleLabel afterDelay:1.6f];

    quadrupLabel.text=@"Quadrup Tap Detected";
    [self performSelector:@selector(eraseMe:)
    withObject:quadrupLabel afterDelay:1.6f];

   -(void)eraseMe:(UITextField *)textField {
    textField.text = @"";

#pragma mark-
    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
     NSUInteger tapCount = [touch tapCount];
    switch (tapCount) {
       case 1:
          [self singleTap];
       case 2:
          [self doubleTap];
      case 3:
        [self tripleTap];
     case 4:
        [self quadrupTap];
     default :




Step 4: Compile and run this application , and when you double, triple, quadruple tap, you should only see one label displayed. See the figure below:

Figure 1: Detecting Tap Application.

You can downloaded SourceCode from here TapTaps 2

Leave a Comment:

1 comment
Dilmer says July 12, 2012

THANK YOU! WOrks great

Add Your Reply