UIScreenEdgePanGestureRecognizer

问题描述 投票:0回答:1

我正在尝试为我的视图控制器实现屏幕边缘平移手势。但问题是,如果尝试为两条边添加边缘平移手势(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)
ios swift gesture uipangesturerecognizer
1个回答
3
投票

是的,你是对的,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")
}
© www.soinside.com 2019 - 2024. All rights reserved.