美文网首页iOS
视图侧滑手势返回上一级视图状态控制

视图侧滑手势返回上一级视图状态控制

作者: survivorsfyh | 来源:发表于2022-04-27 14:54 被阅读0次

    视图侧滑返回上一级视图手势控制的开启(默认开启状态)与关闭控制,具体 code 如下:
    作用域可以在所需视图的 viewDidAppear 和 viewWillDisappear 中进行对其控制;

    开启侧滑返回

    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
        self.navigationController.interactivePopGestureRecognizer.delegate = self;
    }
    

    关闭侧滑返回

    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
        self.navigationController.interactivePopGestureRecognizer.delegate = self;
    }
    

    代理相关 UIGestureRecognizerDelegate

    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
        if (gestureRecognizer == self.navigationController.interactivePopGestureRecognizer) {
            NSLog(@"AAAAAA --- %ld", [self.navigationController.viewControllers count]);// visibleViewController
            if (self.navigationController.viewControllers.count < 2 || self.navigationController.visibleViewController == self.navigationController.viewControllers.firstObject) {
                return NO;
            } else {
                return NO;
            }
        } else {
            return YES;
        }
    }
    

    以上便是此次分享的全部内容,希望能对大家有所帮助!

    相关文章

      网友评论

        本文标题:视图侧滑手势返回上一级视图状态控制

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