No Swipe Back when hiding Navigation Bar in UINavigationController

前端 未结 18 708
生来不讨喜
生来不讨喜 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 07:04

    In my case, to prevent strange effects

    Root view controller

    override func viewDidLoad() {
        super.viewDidLoad()
    
        // Enable swipe back when no navigation bar
        navigationController?.interactivePopGestureRecognizer?.delegate = self
    }
    
    // UIGestureRecognizerDelegate
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        if let navVc = navigationController {
          return navVc.viewControllers.count > 1
        }
        return false
    }
    

提交回复
热议问题