开发中为了使页面具有统一效果,经常会对导航栏进行统一的设置,但是自定义navigationController后,侧滑返回会失效,此时可以在基类里面添加以下方法:
1)最简单的方法:(重新设置手势的delegate)
self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
2)手势:(自己添加手势响应事件)
[self.navigationController.interactivePopGestureRecognizer addTarget:self action:@selector(handleGesture:)];
等同于下面的代码:
@property(nonatomic,strong)UISwipeGestureRecognizer*rightSwipeGestureRecognizer;
self.rightSwipeGestureRecognizer = [[UISwipeGestureRecognizeralloc] initWithTarget:selfaction:@selector(handleSwipes:)];
self.rightSwipeGestureRecognizer.direction =UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:self.rightSwipeGestureRecognizer];
主要是通过设置navigationController.interactivePopGestureRecognizer 此手势的一些属性
self.navigationController.interactivePopGestureRecognizer.enabled = YES | NO; 手势有效与否
self.navigationController.interactivePopGestureRecognizer.delegate = self; 手势的代理,一般会设置为self