在文档中 Coordinating Multiple Gesture Recognizers ,它说:
UIKit normally allows the recognition of only one gesture at a time on a single view. ... For example, in a view that contains both pan and swipe gesture recognizers, swipes are never recognized.
话虽如此,也有一些异常(exception)。例如,在具有两个 UITapGestureRecognizer
的 View 中,both will get fired 的操作.
UIGestureRecognizerDelegate
方法 gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:)
在外部 发挥作用。但是,系统内置的手势识别器(例如 UITapGestureRecognizer
)如何内部决定是否与其他识别器一起工作?或者,连续手势识别器和离散手势识别器在行为方面有什么区别吗?
最佳答案
UIGestureRecognizer
在决策过程中有两个有趣的方法,其中手势识别器可能被“阻止”:
通过调试UITapGestureRecognizer
、UISwipeGestureRecognizer
和UIPanGestureRecognizer
的子类,我发现:
- “双击”识别器会阻止“单击”识别器,但反之则不然
- 平移识别器将阻止滑动识别器
当有多个手势识别器时,第一个识别其手势的识别器默认会将其他识别器呈现为.failed
。
这解释了观察到的行为。
关于ios - UIPanGestureRecognizer 为什么以及如何使 UISwipeGestureRecognizer 静音,而 UITapGestureRecognizers 默认情况下不会相互静音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54403785/