话不多说,直接看代码
需要禁止右滑的controller里面引入代理
@interface SAL5DVC ()<UIGestureRecognizerDelegate>
@end
@implementation SAL5DVC
#pragma mark -- 禁止右滑返回
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
}
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
return NO;
}
@end
完美运行、亲测成功,之前 我是这么写的
- (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];
//开启
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
这么写的问题在于,当进入页面之后,第一次向右滑动是可以返回的,松开第二次,才会有效果,不完美😂😂😂