自定义返回按钮时 右滑返回将会失效
解决方法1
我是直接在集成的UINavigaionController
里直接加一句代码
- (void)viewDidLoad {
[super viewDidLoad];
//遵守代理
self.interactivePopGestureRecognizer.delegate = self;
}
解决方法1
也可以自己响应手势的事件
[self.navigationController.interactivePopGestureRecognizer addTarget:self action:@selector(handleGesture:)];
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
return YES;
}
如上两种方法不推荐使用,因为,比如说在rootViewController的时候这个手势也可以响应,导致整个程序页面不响应;如果在push的同时我触发这个手势,那么会导致navigationBar错乱,甚至crash
解决方法3
也是在集成UINavigaionController
中
@interface EYNavigationController ()<UIGestureRecognizerDelegate,UINavigationControllerDelegate>
@property(nonatomic,weak) UIViewController* currentShowVC;
@end
-(id)initWithRootViewController:(UIViewController *)rootViewController {
EYNavigationController *nvc= [super initWithRootViewController:rootViewController];
self.interactivePopGestureRecognizer.delegate = self;
nvc.delegate = self;
return nvc;
}
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
}
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (navigationController.viewControllers.count == 1)
self.currentShowVC = nil;
else {
self.currentShowVC = viewController;
}
}
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer == self.interactivePopGestureRecognizer) {
return (self.currentShowVC == self.topViewController);
}
return YES;
}
网友评论