这是启用了多个触摸的视图的touchesBegan方法。
- (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);
}
}
我似乎永远不会记录多点触控。只需单击和双击。我错误地认为它就像接触计数一样容易吗?
答案 0 :(得分:1)
您应该在视图上将multipleTouchEnabled
属性设置为YES
,以便让它向您发送多个UITouch
个对象。
除此之外,只传递了更改的UITouch
个对象。如果您触摸某个位置并且不移动手指,之后触摸另一个位置,则只会传递新的触摸对象。您应该在UIEvent
对象中查询视图中的所有活动触摸:
[event touchesForView:self]
答案 1 :(得分:1)
我尝试了三种不同的方式,只有一种可以返回两到五个手指点击。获胜机制是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]);
}
答案 2 :(得分:-1)
获胜机制?有错误和vars甚至没有被使用?
不兼容的Objective-C类型'struct AViewController *',当从不同的Objective-C类型传递'touchesForView:'的参数1时,期望'struct UIView *'
AViewController.m:64:未使用的变量'touch'