iOS实现全屏pop手势

实现全局的pop手势

需要先获取系统手势交互对应interactivePopGestureRecognizer,获取到对应的手势的view
interactivePopGestureRecognizer->UIView->创建新的手势添加到这个UIView上去
这个是利用运行时获取到对应的"_targets",进行了手势重定义。

var outCount : UInt32 = 0
let ivars = class_copyIvarList(UIGestureRecognizer.self, &outCount)!
for i in 0..
ObjC
UIGestureRecognizer *sysGes = nil;
UIView *sysView = nil;
if (self.interactivePopGestureRecognizer) {
sysGes = self.interactivePopGestureRecognizer;
} else return;
if (sysGes.view) {
sysView = sysGes.view;
} else return;

NSDictionary *targetDic = [[sysGes valueForKey:@"_targets"] firstObject];
id target = nil;
SEL sel = nil;
if (targetDic) {
target = [targetDic valueForKey:@"target"];
sel = NSSelectorFromString(@"handleNavigationTransition:");
}else return;
//
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:target action:sel];
[sysView addGestureRecognizer:pan];
Swift
guard let sysGes = interactivePopGestureRecognizer else {return}
guard let popView = sysGes.view else {return}
let targets = sysGes.value(forKey: "_targets") as? [NSObject]
guard let targetDic = targets?.first else {return}
//取出target
guard let target = targetDic.value(forKey: "target") else {return}
let action = Selector(("handleNavigationTransition:"))
//创建自己的pop
let panGes = UIPanGestureRecognizer()
panGes.addTarget(target, action: action)
popView.addGestureRecognizer(panGes)

你可能感兴趣的:(iOS实现全屏pop手势)