Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect two fingers tap on the iPhone?

How do I detect two fingers tap on the iPhone?

like image 253
Paulo Ferreira Avatar asked Apr 25 '10 03:04

Paulo Ferreira


People also ask

How do you use two finger gestures on iPhone?

For example, you can perform a two-finger tap using two fingers on one hand, one finger on each hand, or your thumbs. Instead of selecting an item and double-tapping, you can use a split-tap gesture—touch and hold an item with one finger, then tap the screen with another finger.

How do you turn off two fingers on iPhone?

It's now in System Preferences -> Accessibility -> Zoom. If you are having "pinch" gestures zoom in specific zoom-capable apps, you can turn that gesture off in System Preferences -> Trackpad -> Scroll & Zoom.


2 Answers

If you can target OS 3.2 or above, you can use a UITapGestureRecognizer. It's really easy to use: just configure it and attach it to the view. When the gesture is performed, it'll fire the action of the gestureRecognizer's target.

Example:

UITapGestureRecognizer * r = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewWasDoubleTapped:)];
[r setNumberOfTapsRequired:2];
[[self view] addGestureRecognizer:r];
[r release];

Then you just implement a - (void) viewWasDoubleTapped:(id)sender method, and that will get invoked when [self view] gets double-tapped.

EDIT

I just realized you might be talking about detecting a single tap with two fingers. If that's the case, the you can do

[r setNumberOfTouchesRequired:2]
.

The primary advantage of this approach is that you don't have to make a custom view subclass

like image 98
Dave DeLong Avatar answered Oct 20 '22 15:10

Dave DeLong


If you're not targeting 3.2+:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    if ([touches count] == 2) {
        //etc
    }
}
like image 31
shosti Avatar answered Oct 20 '22 15:10

shosti