ios - UIScreenEdgePanGestureRecognizer
问题描述
我正在尝试为我的视图控制器实现屏幕边缘平移手势。但问题是,如果尝试为两条边缘(UIRectEdge.left、UIRectEdge.right)添加边缘平移手势作为
let screenEdgePanGesture = UIScreenEdgePanGestureRecognizer.init(target: self, action: #selector(self.didPanningScreen))
screenEdgePanGesture.edges = [.right, .left]
screenEdgePanGesture.delegate = self
self.view.addGestureRecognizer(screenEdgePanGesture)
选择器方法未调用。但是边缘平移手势适用于一个边缘,即
let screenEdgePanGesture = UIScreenEdgePanGestureRecognizer.init(target: self, action: #selector(self.didPanningScreen))
screenEdgePanGesture.edges = .right
screenEdgePanGesture.delegate = self
self.view.addGestureRecognizer(screenEdgePanGesture)
解决方案
是的,你是对的,UIScreenEdgePanGestureRecognizer
edges
只接受/使用一个值,所以你需要为左右边缘平移创建两个不同的函数。
斯威夫特 4
let screenEdgePanGestureRight = UIScreenEdgePanGestureRecognizer.init(target: self, action: #selector(self.didPanningScreenRight(_:)))
screenEdgePanGestureRight.edges = .right
screenEdgePanGestureRight.delegate = self
self.view.addGestureRecognizer(screenEdgePanGestureRight)
let screenEdgePanGestureLeft = UIScreenEdgePanGestureRecognizer.init(target: self, action: #selector(self.didPanningScreenLeft(_:)))
screenEdgePanGestureLeft.edges = .left
screenEdgePanGestureLeft.delegate = self
self.view.addGestureRecognizer(screenEdgePanGestureLeft)
@objc func didPanningScreenRight(_ recognizer: UIScreenEdgePanGestureRecognizer) {
print("Right edge penning")
}
@objc func didPanningScreenLeft(_ recognizer: UIScreenEdgePanGestureRecognizer) {
print("Left edge penning")
}
推荐阅读
- python - 如何正确删除带有 xml.etree.elementtree 的子 xml 标记?
- python - 多个标签作为 ML 的训练数据
- java - 两个图像视图碰撞检测的问题[ANDROID]
- google-apps-script - How can I permanently authorize a google sheet for the same user?
- c# - 如何根据选择的模式添加到具有 where 条件的列表?
- excel - 通过 Excel VBA 与雪花的连接未识别表
- c++ - 使用 C++ 的 Anagram 代码有时只能工作
- python - python购物车项目麻烦
- c# - 使用动态属性名称反序列化通用嵌套类型
- java - java class.getResource在vscode中返回null