如何从左到右滑动禁用ViewController解雇?

时间:2013-11-27 04:22:55

标签: ios ipad transition segue viewcontroller

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

我上传了一段视频来帮助解释我的意思。在模拟器和物理设备中都会出现此问题。

http://youtu.be/fyNEDT140TQ

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

3 个答案:

答案 0 :(得分:9)

您需要使用以下代码。 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;
}

答案 1 :(得分:1)

手势正在由UINavigationController.interactivePopGestureRecognizer工作。您可以通过将interactivePopGestureRecognizer.enable设置为NO

来禁用此行为

答案 2 :(得分:0)

Swift 3 +

touches.filter {
           it.action == MotionEvent.ACTION_DOWN 
                or it.action == MotionEvent.ACTION_UP
       }
       .map { it.action == MotionEvent.ACTION_DOWN }
       .distinctUntilChanged() // Avoid repeating events
       .switchMap { state ->
           if (state) {
               Observable.interval(...)
           } else {
               Observable.never()
           }
       }
如果你不知道视图是否有导航控制器,你会想要打开它。

self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false
相关问题