我正在尝试为我的视图控制器实现屏幕边缘平移手势。但是问题是,如果尝试为两个边缘(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")
}
关于ios - UIScreenEdgePanGestureRecognizer,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54689518/