方法一:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
//在其他离开改页面的方法同样加上下面代码
if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
}
方法二
- (void)viewDidAppear:(BOOL)animated {
[superviewDidAppear:animated];
self.isCanSideBack = NO;
if([self.navigationControllerrespondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.delegate=self;
}
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer)gestureRecognizer {
return self.isCanSideBack;
}
- (void)viewDidDisappear:(BOOL)animated {
[superviewDidDisappear:animated];
//在其他离开改页面的方法同样加上下面两句代码
self.isCanSideBack=YES;
if([self.navigationControllerrespondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
}
}
注:如果调用了popToRootViewControllerAnimated,不会走viewDidDisappear。所以需要在返回的方法里面加上相应代码,以便其他页面支持侧滑返回
禁用iOS侧滑返回
本文提供两种方法来实现iOS应用中禁用视图控制器的侧滑返回功能。方法一通过直接禁用和启用交互式弹出手势识别来实现;方法二则利用委托模式来控制是否允许触发侧滑返回。
3868

被折叠的 条评论
为什么被折叠?



