可以通过设置页面的VC.navigationController.interactivePopGestureRecognizer.enabled
来控制当前页面的右滑返回手势是否可用。可以创建一个UIViewController 的分类创建两个类方法。
+ (void)popGestureClose:(UIViewController *)VC
{
// 禁用侧滑返回手势
if ([VC.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
//这里对添加到右滑视图上的所有手势禁用
for (UIGestureRecognizer *popGesture in VC.navigationController.interactivePopGestureRecognizer.view.gestureRecognizers) {
popGesture.enabled = NO;
}
}
}
+ (void)popGestureOpen:(UIViewController *)VC
{
// 启用侧滑返回手势
if ([VC.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
//这里对添加到右滑视图上的所有手势启用
for (UIGestureRecognizer *popGesture in VC.navigationController.interactivePopGestureRecognizer.view.gestureRecognizers) {
popGesture.enabled = YES;
}
}
}
在viewDidAppear:
中禁用手势,viewWillDisappear:
中开启手势。
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[UIViewController popGestureClose:self];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[UIViewController popGestureOpen:self];
}
参考链接
iOS右滑返回手势深度全解和最佳实施方案
网友评论