检测UIIMageView上的两个手指触摸

时间:2011-06-30 06:44:34

标签: iphone cocoa-touch multi-touch

我正试图在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);
    }
}

这段代码真正令人满意的是:这是检测多次点击而非多点触摸。如何检测用户用两根手指触摸物体(多点触控)。

由于

3 个答案:

答案 0 :(得分:3)

使用这样的gestureRecognizers:

UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleFingerTap:)];
twoFingerTap.numberOfTouchesRequired = 2;
[super addGestureRecognizers:twoFingerTap];

http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html

答案 1 :(得分:0)

此时你最好使用手势识别器,用两根手指寻找两个水龙头。

答案 2 :(得分:0)

您可以将事件对象用作

 NSSet *touch = [event allTouches];
 int touchCounts = [touch count];
 if(touchCounts >2)
 {
 //Multitouch.
 }
相关问题