Skip to content

Instantly share code, notes, and snippets.

@imjhk03
Created May 5, 2023 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imjhk03/c18f3aa4371f7ffafcd065d37b8cec7c to your computer and use it in GitHub Desktop.
Save imjhk03/c18f3aa4371f7ffafcd065d37b8cec7c to your computer and use it in GitHub Desktop.
Enable swipe back when navigation bar is hidden
class SwipeBackGestureViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.hidesBarsOnSwipe = true
navigationController?.interactivePopGestureRecognizer?.delegate = self
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidDisappear(animated)
navigationController?.interactivePopGestureRecognizer?.isEnabled = navigationController?.viewControllers.count ?? 0 > 1
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
navigationController?.interactivePopGestureRecognizer?.delegate = nil
}
}
extension SwipeBackGestureViewController: UIGestureRecognizerDelegate {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment