在iOS开发中通常会做的隐藏状态栏或者自定义返回按钮,相应的pop手势也失效了,下面就需要解决下这个问题。
navigationBar.isHidden = true
self.navigationItem.leftBarButtonItem = 自定义返回按钮;
解决方案:
我们在自定义导航控制器里我们自己的手势
class NavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
navigationBar.isHidden = true
setupEdgeGesture()
}
func setupEdgeGesture() {
guard let targets = interactivePopGestureRecognizer!.value(forKey: "_targets") as? [NSObject] else { return }
let targetObjc = targets[0]
let target = targetObjc.value(forKey: "target")
let action = Selector(("handleNavigationTransition:"))
//UIPanGestureRecognizer 全屏手势
//UIScreenEdgePanGestureRecognizer 边缘手势
let panGes = UIScreenEdgePanGestureRecognizer(target: target, action: action)
panGes.delegate = self;
view.addGestureRecognizer(panGes)
}
}
//如果需要监听手势
extension NavigationController: UIGestureRecognizerDelegate {
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if let transitioning = value(forKey: "_isTransitioning") as? Bool {
if transitioning {return false}
}
return viewControllers.count > 1
}
}
这样就可以有效的解决返回pop手势失效问题
各位看官如果发现有什么不对的,请留言或者加qq:286349583,一起讨论,谢谢!!