情况:页面A=>B=>C 继承BaseVC,A禁止侧滑,B、C开启
在baseVC处理
一:在viewDidLoad判断是否是非一级页面,开启系统侧滑
if (self != [self.navigationController.viewControllers firstObject]) {//非一级页开启侧滑
//开启系统自带侧滑返回
if([self.navigationControllerrespondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}
}
二:在viewDidAppear 和viewDidDisappear进行一级页面A的关闭开启侧滑处理
- (void)viewDidAppear:(BOOL)animated
{
[superviewDidAppear:animated];
//禁止页面左侧滑动返回,注意,如果仅仅需要禁止此单个页面返回,还需要在viewWillDisapper下开放侧滑权限
// 禁用返回手势
if (self == [self.navigationController.viewControllers firstObject]) {//一级页
if([self.navigationControllerrespondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
}
}
- (void)viewDidDisappear:(BOOL)animated {
[superviewDidDisappear:animated];
// 开启返回手势
if (self == [self.navigationController.viewControllers firstObject]) {//一级页
if([self.navigationControllerrespondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
}
}