【问题标题】:How do I disable ViewController dismissal on left-to-right swipe?如何在从左到右滑动时禁用 ViewController 关闭?
【发布时间】:2013-11-27 04:22:54
【问题描述】:

有谁知道如何防止视图控制器因从屏幕的最左侧从左向右滑动而被解除(或从 NavigationController 堆栈中弹出)?

我上传了一个视频来帮助解释我的意思。此行为发生在模拟器和物理设备中。

http://youtu.be/fyNEDT140TQ

原因:有人将在屏幕上签名,因此,从屏幕左侧开始将导致导航控制器弹出当前视图控制器(即返回屏幕)。

【问题讨论】:

    标签: ios ipad transition segue viewcontroller


    【解决方案1】:

    您需要使用以下代码。 IOS 6 不支持,所以你要先检查一下

    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)] && [self checkOSVersion] >= 7) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
    
    - (int)checkOSVersion {
    
        NSArray *ver = [[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."];
        int osVerson = [[ver objectAtIndex:0] intValue];
        return osVerson;
    }
    

    【讨论】:

      【解决方案2】:

      手势由 UINavigationController.interactivePopGestureRecognizer 工作。您可以通过将 interactivePopGestureRecognizer.enable 设置为 NO 来禁用此行为

      【讨论】:

        【解决方案3】:

        Swift 3+

        self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false
        

        如果你不知道视图是否有导航控制器,你会想要打开它。

        if self.navigationController?.interactivePopGestureRecognizer?.isEnabled != nil {
            self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false
            } 
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-05-02
          • 2021-05-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-03-04
          相关资源
          最近更新 更多