SwiftUI NavigationBar Hidden, Slipe Back Problem

1. Navigation Bar Hidden

.navigationBarHidden(true)

In SwiftUI Project when we write this code, the NavigationBar will be hidden, but the slip back will also be invalid. At this time, we can add Navigation Extension.

2. Extension

1
2
3
4
5
6
7
8
9
extension UINavigationController: UIGestureRecognizerDelegate {
    override open func viewDidLoad() {
        super.viewDidLoad()
        interactivePopGestureRecognizer?.delegate = self
    }
    public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        return viewControllers.count > 1
    }
}

When we add the extension, then run the project, we will found we did resolve the problem. So easy.

Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy