How do I set up an UIScreenEdgePanGestureRecognizer using Interface Builder?

后端 未结 7 1411
自闭症患者
自闭症患者 2021-02-06 23:48

I can\'t get UIScreenEdgePanGestureRecognizer to work when I create when I add it to my view controller using Interface Builder, so I\'m asking here to establish wh

7条回答
  •  被撕碎了的回忆
    2021-02-07 00:25

    It seems that there is a bug in Xcode 6.4’s interface builder and Swift. Also, Thomas LIU’s answer was also correct: it seems to be necessary to set the .edge property in code, rather than with Interface Builder.

    Even though there are edge checkboxes in IB, they seem to be ignored.

    I solved it this way: Ctrl-drag from the gesture recognizer to the viewController class to create an IBOutlet:

    class ViewController: UIViewController {
        @IBOutlet var leftEdgeGestureRecognizer: UIScreenEdgePanGestureRecognizer!
    

    then, in viewDidLoad:

    leftEdgeGestureRecognizer.edges = .Left
    

    and finally, ctrl-drag from the recognizer to create an IBAction

    @IBAction func swipeFromLeft(sender: AnyObject) {
            print("===> Swipe from left edge.\n")
    }
    

提交回复
热议问题