我有一个覆盖UIGestureRecogniser
设计来检测 2 次触摸,但不一定是一个接一个。
我有:
- (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)preventingGestureRecognizer
{
if ([preventingGestureRecognizer isKindOfClass:[UIRotationGestureRecognizer class]])
{
self.state = UIGestureRecognizerStateCancelled;
return YES;
}
if ([preventingGestureRecognizer isKindOfClass:[UISwipeGestureRecognizer class]])
{
self.state = UIGestureRecognizerStateCancelled;
return YES;
}
//Will prevent a conflict with a 2 finger touch only.
if ([preventingGestureRecognizer isKindOfClass:[UITapGestureRecognizer class]])
{
if (preventingGestureRecognizer.numberOfTouches == 2)
{
self.state = UIGestureRecognizerStateCancelled;
return YES;
}
return NO;
}
self.state = UIGestureRecognizerStateRecognized;
return NO;
}
在我的 MVC 中,我还有一个旋转手势识别器。我的问题是它们是冲突的。@selector
当上述方法应该阻止它时,我的 doubleTap 手势识别器正在调用它的动作。
看起来上面的方法没有被调用。我认为这是因为当两个手指触摸以执行旋转时,以下代码:
- (void)secondTouchRecived
{
self.state = UIGestureRecognizerStateRecognized;
}
调用UIGestureResponders
操作方法并绕过预防方法。我尝试将其更改为,UIGestureRecogniserStateBegan
但这似乎也绕过了预防方法。