This is the touchesBegan method for a view that has multiple touches enabled.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch* touch = [touches anyObject];
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);
}
}
I never seem to log a multi-touch. Just single and double taps. Am I wrong to have assumed it was as easy as getting the count for touches?
I tried three different ways and only one can return two to five finger taps. The winning mechanism is NSSet *touch = [event allTouches];
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch* touch = [touches anyObject];
// the next line will not ever return a multiple tap
if ([touches count] > 1)
NSLog(@"multi-touches %d", [touches count]);
// the next line will return up to 5 (verified) simultaneous taps (maybe more)
NSSet *touch2 = [event allTouches];
if ([touch2 count] > 1)
NSLog(@"multi-touches2 %d", [touch2 count]);
// the next line only returns 1 tap
NSSet *touch3 = [event touchesForView:self];
if ([touch3 count] > 1)
NSLog(@"multi-touches2 %d", [touch3 count]);
}