如何获得多点触控和单点触控事件?
我尝试使用左手触摸移动(不要触摸),现在我在屏幕上单击右手指,但我尝试右手指触摸事件或触摸点(此时左手指仍然在屏幕上移动)
我设置了日志[gesture numberOfTouches]或[gesture numberOfTouchesRequired]。我仍然得到1,而不是得到2。
在我的ViewDidLoad方法中,我设置了以下代码:
- (void)viewDidLoad {
[super viewDidLoad];
self.view.multipleTouchEnabled = YES;
self.view.exclusiveTouch = NO;
UILongPressGestureRecognizer *panelLongPressGestureRecognizer =
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(panelLongPressRecgonizerAction:)];
panelLongPressGestureRecognizer.delegate = self;
//panelLongPressGestureRecognizer.numberOfTapsRequired = 1;
//panelLongPressGestureRecognizer.numberOfTouchesRequired = 1;
panelLongPressGestureRecognizer.minimumPressDuration = 0.001;
[self.view addGestureRecognizer:panelLongPressGestureRecognizer];
UILongPressGestureRecognizer *panelLongDoublePressGestureRecognizer =
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(panelLongPressRecgonizerAction:)];
panelLongDoublePressGestureRecognizer.delegate = self;
panelLongDoublePressGestureRecognizer.numberOfTapsRequired = 2;
panelLongDoublePressGestureRecognizer.numberOfTouchesRequired = 2;
panelLongDoublePressGestureRecognizer.minimumPressDuration = 0.001;
[self.view addGestureRecognizer:panelLongDoublePressGestureRecognizer];
}
- (void)panelLongPressRecgonizerAction:(UILongPressGestureRecognizer *) gestureRecognizer
{
switch (gestureRecognizer.state) {
case UIGestureRecognizerStateBegan:
NSLog(@" === long press began ===");
break;
case UIGestureRecognizerStatePossible:
break;
case UIGestureRecognizerStateChanged:
NSLog(@" === long press changed ===");
[self pressChanged:gestureRecognizer];
break;
case UIGestureRecognizerStateEnded:
NSLog(@" === long press end ===");
break;
case UIGestureRecognizerStateCancelled:
NSLog(@" === long press cancell ===");
break;
case UIGestureRecognizerStateFailed:
NSLog(@" === long press failed ===");
break;
}
NSLog(@" ");
}
- (void) pressChanged:(UILongPressGestureRecognizer *) gesture
{
NSLog(@"moved guesture.number of touches:%ld", [gesture numberOfTouches]);
NSLog(@"moved numberOfTouchesRequired of touches:%ld", [gesture numberOfTouchesRequired]);
}
我仍然得到日志:
2015-05-11 14:25:46.117 DroneG2[7521:1149008] === long press changed ===
2015-05-11 14:25:46.118 DroneG2[7521:1149008] moved guesture.number of touches:1
2015-05-11 14:25:46.118 DroneG2[7521:1149008] moved numberOfTouchesRequired of touches:1
有人知道我的代码中的问题在哪里吗?
我想在移动时获得其他手指触摸点或事件?
或者有其他方法可以实现多点触控坐标序列?
非常感谢你。答案 0 :(得分:0)
对于复杂的触摸事件使用 UIResponder的方法..
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
计算和区分触摸事件。