2

我有一个覆盖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但这似乎也绕过了预防方法。

4

1 回答 1

1

通过将旋转、滑动和点击手势识别器传递给您的自定义手势识别器上的 requireGestureRecognizerToFail: 来指定依赖项怎么样?这将阻止您的手势识别器在旋转识别器有机会处理触摸之前转换到已识别状态。

于 2012-06-19T17:38:26.880 回答