[英]Simultaneous use of touch down and touch up gesture recognizers
我在UIView
上使用了两个手势识别器。 一个是标准的UITapGestureRecognizer
,另一个是我编写的非常简单的触地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无效。 如果添加日志记录以查看与委托的交互以及在我自己的识别器内部的交互,则可以看到对于短按和长按而言,调用顺序是相同的-除了对补全识别器的调用之外。 我做错了什么?
为什么不直接从UILongPressGestureRecognizer
检查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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.