[英]Detect Two finger touch on UIIMageView
I am trying to detect two finger touch on a UIImageView object.我正在尝试检测 UIImageView object 上的两个手指触摸。 In xib I had set multi-touch enbled.
在 xib 中,我设置了多点触控。 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).
如何检测用户用两根手指(多点触控)触摸 object。
Thanks谢谢
Use gestureRecognizers like this:像这样使用手势识别器:
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 http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html
At this point you are really better off using a gesture recognizer, looking for two taps with two fingers.在这一点上,你最好使用手势识别器,用两根手指寻找两次点击。
You can use event object for the same as您可以使用事件 object 与
NSSet *touch = [event allTouches];
int touchCounts = [touch count];
if(touchCounts >2)
{
//Multitouch.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.