【问题标题】:UIScreenEdgePanGestureRecognizerUIScreenEdgePanGestureRecognizer
【发布时间】:2019-02-14 11:38:24
【问题描述】:

我正在尝试为我的视图控制器实现屏幕边缘平移手势。但问题是,如果尝试为两条边缘(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】:

    是的,你是对的,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")
    }
    

    【讨论】:

    • @AtulParmar - 您是否有在笔记滑动动作旁边添加屏幕边缘平移手势的经验?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-11
    • 2014-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多