我正试图在UIImageView对象上检测到两个手指触摸。在xib我设置了多点触控。 然后我实现了以下代码:
- (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);
}
}
这段代码真正令人满意的是:这是检测多次点击而非多点触摸。如何检测用户用两根手指触摸物体(多点触控)。
由于
答案 0 :(得分:3)
使用这样的gestureRecognizers:
UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleFingerTap:)];
twoFingerTap.numberOfTouchesRequired = 2;
[super addGestureRecognizers:twoFingerTap];
答案 1 :(得分:0)
此时你最好使用手势识别器,用两根手指寻找两个水龙头。
答案 2 :(得分:0)
您可以将事件对象用作
NSSet *touch = [event allTouches];
int touchCounts = [touch count];
if(touchCounts >2)
{
//Multitouch.
}