No Swipe Back when hiding Navigation Bar in UINavigationController

前端 未结 18 680
生来不讨喜
生来不讨喜 2020-12-04 06:34

I love the swipe pack thats inherited from embedding your views in a UINavigationController. Unfortunately i cannot seem to find a way to hide the Naviga

18条回答
  •  失恋的感觉
    2020-12-04 06:57

    My solution is to directly extend the UINavigationController class :

    import UIKit
    
    extension UINavigationController: UIGestureRecognizerDelegate {
    
        override open func viewDidAppear(_ animated: Bool) {
            super.viewDidAppear(animated)
    
            self.interactivePopGestureRecognizer?.delegate = self
        }
    
        public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
            return self.viewControllers.count > 1
        }
    
    }
    

    This way, all navigation controllers will be dismissable by sliding.

提交回复
热议问题