关于导航栏右滑返回的工具库 FDFullscreenPopGesture 是 OC 版本,用了 runtime 等各种骚操作
关于 swift ,我在 UINavigationController 的 viewDidLoad 方法中
class GMNavigationController: UINavigationController { override func viewDidLoad() { super.viewDidLoad() self.addPanGes() } /// 将导航栏的右滑手势添加到 view 上面 func addPanGes() { interactivePopGestureRecognizer?.delegate = self guard let targets = interactivePopGestureRecognizer?.value(forKey: "_targets") as?[AnyObject] else { return } let dict = targets[0] //拿到action let target = dict.value(forKey: "target") as Any //通过字典无法拿到action,这里通过Selector方法包装action let action = Selector(("handleNavigationTransition:")) //拿到target action 创建pan手势并添加到全屏view上 let gesture = UIPanGestureRecognizer(target: target, action: action) view.addGestureRecognizer(gesture)
// 这里需要将导航栏的右滑手势去掉 self.interactivePopGestureRecognizer?.isEnabled = false } }
这样就可以达到的效果了。