Phil Hudson Phil Hudson - 6 months ago 212
iOS Question

Disable swipe back gesture in Swift

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.

I've tried a variety of solutions including:

self.navigationController?.interactivePopGestureRecognizer.enabled = false


self.navigationController.interactivePopGestureRecognizer.delegate = self

func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer!) -> Bool {
return false;

Is there a new method of doing this or some other method that works?


You could disable it but that would not be to recommended as most iOS users go back by swiping and less by pressing the back button. If you want to disable it it would be more reasonable to use a modal segue instead of a push segue which is not that big of a transfer. If you really want to get rid of the swipe to go back function I would just disable the back button and have a done button on the top right of the screen.

self.navigationController.navigationItem.backBarButtonItem.enabled = false