目的:当push到下一控制器时,里面整个界面用手势侧滑是可以返回的
步骤:1.自己写一个UINavigationController子类
import UIKit
class QNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
//校验手势是否有值
guard let interacionGes = interactivePopGestureRecognizer else {
return
}
/*
//通过运行时获取对应的手势属性
var count : UInt32 = 0
let ivars = class_copyIvarList(UIGestureRecognizer.self, &count)!
for i in 0..<count {
let ivar = ivars[Int(i)]
let namep = ivar_getName(ivar)
let name = String(cString: namep!)//属性名称
print(name)
}
*/
guard let values = interacionGes.value(forKeyPath: "_targets") as? [NSObject] else{
return
}
guard let objc = values.first else {
return
}
//根据KVC取出action 和target
let target = objc.value(forKeyPath: "target")
let action = Selector(("handleNavigationTransition:"))
//下面是获取不到action的会奔溃
// let action = objc.value(forKeyPath: "action") as? Selector
//创建自己的手势 将系统的手势去代替自己创建的手势
let panGes = UIPanGestureRecognizer(target: target, action: action)
view.addGestureRecognizer(panGes)
}
}
2.将该UINavigationController的子类作为你的导航控制器即可