很简单:建一个UINavigationController分类:
.h文件:
#import <UIKit/UIKit.h>
@interface UINavigationController (RightBack) <UIGestureRecognizerDelegate>
@end
#import "UINavigationController+RightBack.h"
@implementation UINavigationController (RightBack)
-(void)viewDidLoad{
[super viewDidLoad];
//
id target = self.interactivePopGestureRecognizer.delegate;
//
SEL handler = NSSelectorFromString(@"handleNavigationTransition:");
// 获取添加系统边缘触发手势的View
UIView *targetView = self.interactivePopGestureRecognizer.view;
// 创建pan手势 作用范围是全屏
UIPanGestureRecognizer * fullScreenGes = [[UIPanGestureRecognizer alloc]initWithTarget:target action:handler];
fullScreenGes.delegate = self;
[targetView addGestureRecognizer:fullScreenGes];
// 关闭边缘触发手势 防止和原有边缘手势冲突
[self.interactivePopGestureRecognizer setEnabled:NO];
}
// 防止导航控制器只有一个rootViewcontroller时触发手势
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
UIPanGestureRecognizer *rr = (UIPanGestureRecognizer *)gestureRecognizer;
//解决与左滑手势冲突
CGPoint translation = [rr translationInView:gestureRecognizer.view];
if (translation.x <= 0) {
return NO;
}
return self.childViewControllers.count == 1 ? NO : YES;
}
@end