ios - UIPanGestureRecognizer 为什么以及如何使 UISwipeGestureRecognizer 静音,而 UITapGestureRecognizers 默认情况下不会相互静音?

标签 ios swift uikit uigesturerecognizer

在文档中 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 在决策过程中有两个有趣的方法,其中手势识别器可能被“阻止”:

通过调试UITapGestureRecognizerUISwipeGestureRecognizerUIPanGestureRecognizer 的子类,我发现:

  • “双击”识别器会阻止“单击”识别器,但反之则不然
  • 平移识别器将阻止滑动识别器

当有多个手势识别器时,第一个识别其手势的识别器默认会将其他识别器呈现为.failed

这解释了观察到的行为。

关于ios - UIPanGestureRecognizer 为什么以及如何使 UISwipeGestureRecognizer 静音,而 UITapGestureRecognizers 默认情况下不会相互静音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54403785/

相关文章:

ios - 粘贴长文本时 UITextView 动态高度滚动不起作用

iphone - UTF8 iPhone 无法读取阿姆哈拉语字母

ios - UIScrollView下拉父 View

objective-c - 应用程序在后台时不显示 iOS UILocalNotification

ios - EKReminder 没有设置日历

iphone - 在 iPhone 应用程序中关闭拼写检查器

ios - 在 objective-c 中更改应用程序扩展的屏幕旋转

ios - 如何转换 UTC

swift - NSFetchedResultsController - 排序为数字但字符串字段

ios - LLDB( swift ): Casting Raw Address into Usable Type