在自定義的navVC中,用kvc的方式獲取到系統(tǒng)返回手勢的target和action 賦值給自定義的pan手勢 的target 和action,pan手勢就實現(xiàn)了系統(tǒng)手勢一樣的功能
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor grayColor];
UIGestureRecognizer *gesture = self.interactivePopGestureRecognizer;
// NSLog(@"gesture: %@", gesture);
UIView *navPopView = gesture.view;
id targets = [gesture valueForKey:@"_targets"];
// NSLog(@"targets: %@", targets);
//獲取手勢
id targetObjc = [targets firstObject];
// NSLog(@"targetObjc: %@", targetObjc);
//獲取手勢的target
id target = [targetObjc valueForKey:@"target"];
// NSLog(@"target: %@", target);
//直接崩潰
{
// id action = [targetObjc valueForKey:@"action"];
// NSLog(@"action: %@", action);
}
//獲取手勢綁定的方法SEL
SEL sel = NSSelectorFromString(@"handleNavigationTransition:");
// NSLog(@"sel: %p", &sel);
//將系統(tǒng)手勢返回的target和SEL綁定到自定義的pan手勢上
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:target action:sel];
[navPopView addGestureRecognizer:pan];
NSLog(@"---%s----%@", __PRETTY_FUNCTION__, [navPopView valueForKey:@"gestureRecognizers"]);
}