OC中一遍leftBarButtonItem与右滑冲突,网上有很多代码贴出来,在自定义的UINavigationController设置一遍就可以了。
但是最近我在swift的项目中,把原先的自定义UINavigationController加入项目中使用,发现右滑返回还是无效。
这个小问题,搞了我两天……
下面是我生效的代码:
class JJNavigationVC: UINavigationController,UINavigationControllerDelegate {
var popDelegate: UIGestureRecognizerDelegate?
override func viewDidLoad() {
super.viewDidLoad()
self.popDelegate = self.interactivePopGestureRecognizer?.delegate
self.delegate = self
}
// MARK: - UINavigationControllerDelegate方法
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
if viewController == self.viewControllers[0] {
self.interactivePopGestureRecognizer!.delegate = self.popDelegate
} else {
self.interactivePopGestureRecognizer!.delegate = nil
}
}
}