两个 UIGestureRecognizer
我有两个 UIGestureRecognizers ,用于同时识别两者的视图。我希望完成或取消主要手势也能终止其他手势。那么,有没有办法杀死活动手势,即强制取消活动手势识别器?
I have two UIGestureRecognizers
for a view that recognizes both simultaneously. I'd like for the finish or cancellation of the primary gesture to kill the other gesture as well. So, is there a way to kill an active gesture, i.e. force the cancellation of an active gesture recognizer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您只想在主要手势结束或取消时终止辅助手势,因此请在主要手势的手势处理程序中执行此操作。
这似乎是取消手势的唯一方法。
You can use
requireGestureRecognizerToFail:
to declare a dependency.这将在成功识别主要手势后终止次要手势。如果取消主要手势,则不提供此类工具。您可以在
UIGestureRecognizerStateCancelled< 上的主手势的手势处理程序中将辅助手势的
enabled
标志翻转为NO
和YES
/code> 但这看起来并不优雅。Since you want to kill the secondary gesture only when the primary gesture has ended or cancelled, do this in the gesture handler of the primary gesture.
This seems to be the only way you can cancel a gesture.
You can use
requireGestureRecognizerToFail:
to declare a dependency.This will kill the secondary gesture on successful identification of the primary gesture. There is no such tool provided if the primary gesture is cancelled. You can probably flip the
enabled
flag of the secondary gesture toNO
andYES
in the gesture handler of the primary gesture onUIGestureRecognizerStateCancelled
but that doesn't seem elegant.根据手势,您可能想要同时拥有两者。我遇到了一个问题,手势相互干扰,有一段时间有类似于这个解决方案的东西。我尝试使用的两个手势是捏合和旋转手势。理想情况下,我希望用户能够在两者之间平滑过渡,而不必取消我设法实现的目标。我已经写了我是如何在这里做到这一点的,并提供了一个如何做的视频我希望这个可能会帮助某人。
Depending on the gestures you may want to have both. I ran up against a problem where gestures were interfering with one another and for a while had something similar to this solution. The two gestures I was trying to use was the pinch and rotate gesture. Ideally I wanted the user to be able to smoothly transition between the two without having to cancel one which I managed to achieve. I have written up how I did it here and provided a how to video I hope this might help someone.