4

我在我的UIView. 一个是标准UITapGestureRecognizer的,另一个是我写的非常简单的着陆识别器:

@implementation TouchDownGestureRecognizer

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    if (self.state == UIGestureRecognizerStatePossible) {
        self.state = UIGestureRecognizerStateRecognized;
    }
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    self.state = UIGestureRecognizerStateFailed;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    self.state = UIGestureRecognizerStateFailed;
}

@end

只有当我为它们都分配一个包含此方法的委托时,它们才能一起工作:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}

一切正常,但是当我长按该视图时,触摸识别器会触发而触摸识别器不会触发。对于短按,一切都很好,它们都开火了。

我实现了所有方法UIGestureRecognizerDelegate以返回 YES 无济于事。如果我正在添加日志记录以查看与委托的交互以及在我自己的识别器内部,我可以看到对于短敲和长敲,调用顺序是相同的——除了对修饰识别器的调用。我做错了什么?

4

1 回答 1

6

为什么不直接从 中检查 touchUp UILongPressGestureRecognizer

-(void)selectionDetected:(UILongPressGestureRecognizer*)longPress
{
    if(longPress.state==1)
    {
       //long Press is being held down
    }
    else if(longPress.state==3)
    {
        //the touch has been picked up
    }
}
于 2013-08-05T18:37:45.997 回答