interactivePopGestureRecognizer corrupts navigation stack on root view controller

后端 未结 5 1474
攒了一身酷
攒了一身酷 2021-02-12 11:19

In my UINavigationController I added custom back buttons with the side effect that it is not possible anymore to swipe left to right to pop the view controller and

5条回答
  •  盖世英雄少女心
    2021-02-12 12:06

    Implement UINavigationControllerDelegate for your navigation controller and enable/disable the gesture recognizer there.

    // Fix bug when pop gesture is enabled for the root controller
    func navigationController(navigationController: UINavigationController, didShowViewController viewController: UIViewController, animated: Bool) {
        self.interactivePopGestureRecognizer?.enabled = self.viewControllers.count > 1
    }
    

    Keeping the code independent from the pushed view controllers.

提交回复
热议问题