Disable swipe back gesture in Swift

后端 未结 10 1491
轻奢々
轻奢々 2020-12-02 09:47

Been looking around on here for a while but can\'t seem to find a working solution.

I\'m trying to disable the swipe to go back to previous view gesture, in Swift.

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 10:29

    I was able to do this by returning false in gestureRecognizerShouldBegin

    class ViewController2: UIViewController, UIGestureRecognizerDelegate {
    ...
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        self.navigationController?.interactivePopGestureRecognizer.delegate = self
    }
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        return false
    }
    

提交回复
热议问题