遵循代理 UIGestureRecognizerDelegate
UIGestureRecognizer *gesture = self.interactivePopGestureRecognizer;
gesture.enabled = NO;
UIView *gestureView = gesture.view;
UIPanGestureRecognizer *popRecognizer = [[UIPanGestureRecognizer alloc] init];
popRecognizer.delegate = self;
popRecognizer.maximumNumberOfTouches = 1;
[gestureView addGestureRecognizer:popRecognizer];
NSMutableArray *_targets = [gesture valueForKey:@"_targets"];
id gestureRecognizerTarget = [_targets firstObject];
id navigationInteractiveTransition = [gestureRecognizerTarget valueForKey:@"_target"];
SEL handelTransition = NSSelectorFromString(@"handleNavigationTransition:");
[popRecognizer addTarget:navigationInteractiveTransition action:handelTransition];
代理方法
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
//这里有两个条件不允许手势 1 当前控制器为根控制器 2 如果这个push pop 动画正在执行(私有属性)
if (self.childViewControllers.count == 1) {
return NO;
}
//直播页面不允许滑动返回
UIViewController *vc = [self.childViewControllers lastObject];
if ([vc isKindOfClass:NSClassFromString(@"ChatViewController")]) {
return NO;
}
if ([[self valueForKey:@"_isTransitioning"] boolValue]) {
return NO;
}
return YES;
// return self.viewControllers.count != 1 && ![[self valueForKey:@"_isTransitioning"] boolValue];
}
网友评论