views:

408

answers:

4

Anyone know how to detect two fingers tap on iPhone?

Thanks in advance!

+1  A: 

Set the multiTouchEnabled property to YES.

Marcelo Cantos
A: 

If your requirements allow, use UITapGestureRecognizer. Otherwise, implement the following UIResponder methods in your custom UIView:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;

Track throughout to see how many touches there were and whether or not they moved more than your tap/drag threshold. You must implement all four methods.

drawnonward
+1  A: 

If you're not targeting 3.2+:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    if ([touches count] == 2) {
        //etc
    }
}
eman
Thanks eman! Solved my problem!
Paulo Ferreira
+4  A: 

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

Dave DeLong