美文网首页
iOS-侧滑溜冰问题修复

iOS-侧滑溜冰问题修复

作者: aggie1024 | 来源:发表于2021-11-29 10:22 被阅读0次

    项目中用到了JXCategoryView并且需要侧滑手势,在VC中用到了self.interactivePopGestureRecognizer.delegate = self;唤起手势,但是出现溜冰bug[侧滑之后 松手自动划过去]
    解决方案是:
    在TPNavigationController的push方法中,增加判断即可
    if([self respondsToSelector:@selector(interactivePopGestureRecognizer)]){
    self.interactivePopGestureRecognizer.enabled = YES;
    self.interactivePopGestureRecognizer.delegate = nil;
    }
    完整为:

    - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
        if (self.childViewControllers.count >0) {
            viewController.hidesBottomBarWhenPushed = YES;
        }
        if([self respondsToSelector:@selector(interactivePopGestureRecognizer)]){
            self.interactivePopGestureRecognizer.enabled = YES;
            self.interactivePopGestureRecognizer.delegate = nil;
        }
        [super pushViewController:viewController animated:animated];
    }
    

    补充内容:
    自定义的导航栏如果不相应侧滑手势,严谨做法为:
    在viewDidAppear中添加代理,在viewWillDisappear中将代理置为nil,负责就会出现连续返回或者侧滑溜冰等混乱场景

    - (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];
        // 侧滑手势代理关闭【否则不置为nil会出现连环返回】
        if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
            self.navigationController.interactivePopGestureRecognizer.delegate = nil;
        }
    }
    

    相关文章

      网友评论

          本文标题:iOS-侧滑溜冰问题修复

          本文链接:https://www.haomeiwen.com/subject/fugkxrtx.html