Reputation: 5232
I am trying to detect two finger touch on a UIImageView object. In xib I had set multi-touch enbled. Then I implemented the following code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//NSLog(@"%@", [[touches anyObject] class]);
UITouch* touch = [touches anyObject];
NSLog(@"%@", [touch class]);
if ([touches count] > 1)
NSLog(@"multi touches: %d fingers", [touches count]);
NSUInteger numTaps = [touch tapCount];
if (numTaps == 1) {
NSLog(@"single tap");
} else {
NSLog(@"multi tap: %d", numTaps);
}
}
What actually happning with this code is: This is detecting multiple taps not multi-touch. How can I detect that user touched on object with two finger(Multi-Touch).
Thanks
Upvotes: 2
Views: 4925
Reputation: 22726
You can use event object for the same as
NSSet *touch = [event allTouches];
int touchCounts = [touch count];
if(touchCounts >2)
{
//Multitouch.
}
Upvotes: 0
Reputation: 612
Use gestureRecognizers like this:
UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleFingerTap:)];
twoFingerTap.numberOfTouchesRequired = 2;
[super addGestureRecognizers:twoFingerTap];
Upvotes: 4
Reputation: 75058
At this point you are really better off using a gesture recognizer, looking for two taps with two fingers.
Upvotes: 0