我在我的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,但仍然无济于事。如果我添加日志以查看与委托的交互及自己的识别器内部情况,我可以看到对于短时间和长时间的点击,调用顺序是相同的——除了抬起触摸识别器的调用。我做错了哪些事情吗?
minimumPressDuration
设置为 0,现在可以正常工作了。 - Sergey Mikhanov