UIGestureRecognizerDelegate

  A set of methods implemented by the delegate of a gesture recognizer to fine-tune an app’s gesture-recognition behavior.  

  一个设置手势识别器委托实现的方法,用于微调应用程序的手势识别行为。

  Overview

  The delegates receive messages from a gesture recognizer, and their responses to these messages enable them to affect the operation of the gesture recognizer or to specify a relationship between it and another gesture recognizer, such as allowing simultaneous recognition or setting up a dynamic failure requirement.

  这些委托从手势识别器接收消息,它们会响应这些消息以能够影响到手势识别器的操作或指定它与另外一个手势识别器的关系,例如,允许同时识别或设置动态的失败需求。

  An example of a situation where dynamic failure requirements are useful is in an app that attaches a screen-edge pan gesture recognizer to a view. In this case, you might want all other relevant gesture recognizers associated with that view's subtree to require the screen-edge gesture recognizer to fail so you can prevent any graphical glitches that might occur when the other recognizers get canceled after starting the recognition process. To do this, you could use code similar to the following:

  在应用程序中动态的失败需求例子,应用程序将屏幕边缘的pan手势绑定到一个视图上,在这种情况下,您可能希望与该视图的子树关联的所有其他相关手势识别器都要求屏幕边缘手势识别器失败,这样就可以防止在启动识别过程后取消其他识别器时可能出现的任何图形错误。如果想做到这一点,你可以使用类似于下面的代码:

let myScreenEdgePanGestureRecognizer = UIScreenEdgePanGestureRecognizer(target: self, action:#selector(handleScreenEdgePan))
myScreenEdgePanGestureRecognizer.delegate = self
// Configure the gesture recognizer and attach it to the view. ... func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool {
guard let myView = myScreenEdgePanGestureRecognizer.view,
let otherView = otherGestureRecognizer.view else { return false } return gestureRecognizer == myScreenEdgePanGestureRecognizer &&
otherView.isDescendant(of: myView)}

gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:)

  Asks the delegate if two gesture recognizers should be allowed to recognize gestures simultaneously.

  询问委托代理是否允许两个手势识别器同时识别手势。

optional func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer,
shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool

 Return Value

  true to allow both gestureRecognizer and otherGestureRecognizer to recognize their gestures simultaneously. The default implementation returns false—no two gestures can be recognized simultaneously.

  如果为真的时候允许手势识别器与其他手势识别器同时识别他们的手势。默认实现返回false,不能同时识别两个手势。

 Discussion

  This method is called when recognition of a gesture by either gestureRecognizer or otherGestureRecognizer would block the other gesture recognizer from recognizing its gesture. Note that returning true is guaranteed to allow simultaneous recognition; returning false, on the other hand, is not guaranteed to prevent simultaneous recognition because the other gesture recognizer's delegate may return true.

  当手势识别器或其他手势识别器对某个手势的识别会阻止其他手势识别器识别其手势时,就会调用此方法。注意,返回true保证允许同时识别;另一方面,返回false不能保证防止同时识别,因为其他手势识别器的委托可能返回true。

最新文章

  1. android -- 之PopupWindow的使用
  2. Leetcode 344 Reverse String 字符串处理
  3. Java基础-关键字-final
  4. (转)js闭包初入门
  5. Bitmap 之 getPixels() 的 stride
  6. 【solr】 solr 5.4.1 和tomcat 基础环境搭建
  7. C#高性能大容量SOCKET并发(一):IOCP完成端口例子介绍(转)
  8. Lua - 基础语法
  9. K - Transformation-hdu 4578(多操作混合区间更新)线段树
  10. HDU 3468 BFS+二分匹配
  11. Jupyter 初体验
  12. Mina框架(实战详解)
  13. 使用cookie时出现“未将对象引用设置到对象实例”
  14. WPF PasswordBox不支持绑定解决方法
  15. android的事件分发传递机制
  16. VUE2.0 饿了吗视频学习笔记(五):父子对象传递、显示图片
  17. Android之设计模式
  18. kubernetes pod、service文件yaml模版格式
  19. ncl 函数源码 gc_inout
  20. Failed to create the Java Virtual Machine

热门文章

  1. 公众号在线Markdown编辑器,支持公式
  2. selenium(java)浏览器多窗口切换处理
  3. HT Vue 集成
  4. App自动化测试-1.App自动化介绍和环境搭建
  5. Selenium+Java(九)Selenium键盘与鼠标事件
  6. Server MyEclipse Tomcat v7.0 was unable to start within 45 seconds. If the server requires more time
  7. php方法注释
  8. PHP函数include include_once require和require_once的区别
  9. springboot+apache前后端分离部署https
  10. 2019-2020-1 20199304《Linux内核原理与分析》第七周作业