由于想在项目中加入,任意界面都能够在边缘滑动返回上一级,于是使用了 UIGestureRecognizerDelegate
self.navigationController.interactivePopGestureRecognizer.delegate = self;
却引入了问题:
应用中使用了MMDrawerController实现左边侧边栏功能。在主页进入二级界面后。再返回。当多次在边缘尝试滑动打开侧边栏时可以必现bug(整个界面无法操作),当再次尝试边缘滑动时,发现从右边缘出现了上次打开的二级菜单。
解决方案:
在导航栏基类中需要遵守 UINavigationControllerDelegate
- (void)viewDidLoad {
[super viewDidLoad];
__weak HyBaseNavgationController *weakSelf = self;
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.interactivePopGestureRecognizer.delegate = weakSelf;
self.delegate = weakSelf;
}
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if ( [self respondsToSelector:@selector(interactivePopGestureRecognizer)]&&animated == YES ){
self.interactivePopGestureRecognizer.enabled = NO;
}
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animate {
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]){
if (navigationController.childViewControllers.count == 1) {
self.interactivePopGestureRecognizer.enabled = NO;
}else
self.interactivePopGestureRecognizer.enabled = YES;
}
}
本文介绍了解决iOS应用中边缘滑动返回功能与MMDrawerController左侧菜单冲突的问题。通过调整UINavigationControllerDelegate方法,禁用和启用交互式弹出手势识别器,确保滑动返回与侧边栏功能正常工作。
4641

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



