关于在APP中边缘滑动返回卡顿问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/my_programe_life/article/details/77772684

由于想在项目中加入,任意界面都能够在边缘滑动返回上一级,于是使用了 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;
    }

}
展开阅读全文

没有更多推荐了,返回首页