自定義返回按鈕時(shí) 右滑返回將會(huì)失效
解決方法1
我是直接在集成的UINavigaionController里直接加一句代碼
- (void)viewDidLoad {
[super viewDidLoad];
//遵守代理
self.interactivePopGestureRecognizer.delegate = self;
}
解決方法1
也可以自己響應(yīng)手勢(shì)的事件
[self.navigationController.interactivePopGestureRecognizer addTarget:self action:@selector(handleGesture:)];
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
return YES;
}
如上兩種方法不推薦使用,因?yàn)?,比如說(shuō)在rootViewController的時(shí)候這個(gè)手勢(shì)也可以響應(yīng),導(dǎo)致整個(gè)程序頁(yè)面不響應(yīng);如果在push的同時(shí)我觸發(fā)這個(gè)手勢(shì),那么會(huì)導(dǎo)致navigationBar錯(cuò)亂,甚至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;
}