1 - (void)setupGetsInNav 2 { 3 UIGestureRecognizer *gesture = self.interactivePopGestureRecognizer; 4 gesture.enabled = NO; 5 UIView *gestureView = gesture.view; 6 7 UIPanGestureRecognizer *popRecognizer = [[UIPanGestureRecognizer alloc] init]; 8 popRecognizer.delegate = self; 9 popRecognizer.maximumNumberOfTouches = 1;10 [gestureView addGestureRecognizer:popRecognizer];11 /**12 * 获取系统手势的target数组13 */14 NSMutableArray *_targets = [gesture valueForKey:@"_targets"];15 /**16 * 获取它的唯一对象,我们知道它是一个叫UIGestureRecognizerTarget的私有类,它有一个属性叫_target17 */18 id gestureRecognizerTarget = [_targets firstObject];19 /**20 * 获取_target:_UINavigationInteractiveTransition,它有一个方法叫handleNavigationTransition:21 */22 id navigationInteractiveTransition = [gestureRecognizerTarget valueForKey:@"_target"];23 /**24 * 通过前面的打印,我们从控制台获取出来它的方法签名。25 */26 SEL handleTransition = NSSelectorFromString(@"handleNavigationTransition:");27 /**28 * 创建一个与系统一模一样的手势,我们只把它的类改为UIPanGestureRecognizer29 */30 [popRecognizer addTarget:navigationInteractiveTransition action:handleTransition];31 32 }
1 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {2 /**3 * 这里有两个条件不允许手势执行,1、当前控制器为根控制器;2、如果这个push、pop动画正在执行(私有属性)4 */5 return self.viewControllers.count != 1 && ![[self valueForKey:@"_isTransitioning"] boolValue];6 }
只需要在全局的导航控制器中添加上边代码即可