思路: 新建一个BaseVC, BaseVC里实现右划事件的代理, 所有的VC都继承于这个BaseVC.
.h
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface BaseViewController : UIViewController
@end
NS_ASSUME_NONNULL_END
.m
#import "BaseViewController.h"
@interface BaseViewController ()<UIGestureRecognizerDelegate>
@end
@implementation BaseViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
@end
self.navigationController.interactivePopGestureRecognizer.delegate = self;
也可以写成
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
上面的UIGestureRecognizerDelegate就可以不引入了.