我在我的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 无济于事。如果我正在添加日志记录以查看与委托的交互以及在我自己的识别器内部,我可以看到对于短敲和长敲,调用顺序是相同的——除了对修饰识别器的调用。我做错了什么?