Disable swipe back gesture in Swift

后端 未结 10 1476
轻奢々
轻奢々 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:18

    I generally make sure that swipe back is enabled in as many places as possible, even adding a custom gesture recognizer to add it to modal screens. However for an authentication and download process in my app I start the process with a modal navigation controller and then push the view for each next step. However, once it's completed I want to prevent them from backing up into the authentication screens.

    For this scenario I've been using:

    navigationController?.interactivePopGestureRecognizer?.isEnabled = false
    navigationItem.hidesBackButton = true
    

    in viewWillAppear() on the final screen. You can undo these in viewWillDisappear() if you're pushing another view and need them there.

提交回复
热议问题