要屏蔽/开启某一个UIViewController的系统自带的右滑手势实现返回的功能。如下步骤:
(1)在.m文件中实现如下代码:(一般写在viewDidLoad方法中)
- (void)viewDidLoad {
[super viewDidLoad];
if ([[UIDevice currentDevice].systemVersion floatValue]>=7.0) {
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
}
}
(2)在此viewController的头文件中加入代理<UIGestureRecognizerDelegate>;
@interface BaseViewController ()<UIGestureRecognizerDelegate>
@end
(2)实现代理方法
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
if ([self.navigationController.viewControllers count] == 1) {
return NO;
}else{
return YES;
}
}