给导航控制器添加一个全屏滑动返回的手势。类似QQ.微博的效果
//1获取系统的pop手势
guard let systemGes = interactivePopGestureRecognizer else { return }
//2获取手势添加的view
guard let gesView = systemGes.view else { return }
//3.1获取target action
target和action不能够直接拿到。因此要使用运行时和KVO
//利用运行时机制查看对应属性名称
/*
var count : UInt32 = 0
let ivars = class_copyIvarList(UIGestureRecognizer.self, &count)!
for i in 0..<count {
let ivar = ivars[Int(i)]
let name = ivar_getName(ivar)
//打印所有属性
print(String(cString: name!))
}
*/
在运行时中我们找到了target image
let targets = systemGes.value(forKey: "_targets") as? [NSObject]
guard let targetObjc = targets?.first else { return }
// print(targetObjc)//打印拿到到的target字典
使用KVO取出需要的属性 image 拿到了pan的key
//3.2取出target
guard let target = targetObjc.value(forKey: "target") else { return }
//3.3取出target
let action = Selector(("handleNavigationTransition:"))
添加进去
//4 创建自己的手势pan
let panGes = UIPanGestureRecognizer()
gesView.addGestureRecognizer(panGes)
panGes.addTarget(target, action: action)