【发布时间】:2013-11-27 04:22:54
【问题描述】:
有谁知道如何防止视图控制器因从屏幕的最左侧从左向右滑动而被解除(或从 NavigationController 堆栈中弹出)?
我上传了一个视频来帮助解释我的意思。此行为发生在模拟器和物理设备中。
原因:有人将在屏幕上签名,因此,从屏幕左侧开始将导致导航控制器弹出当前视图控制器(即返回屏幕)。
【问题讨论】:
标签: ios ipad transition segue viewcontroller
有谁知道如何防止视图控制器因从屏幕的最左侧从左向右滑动而被解除(或从 NavigationController 堆栈中弹出)?
我上传了一个视频来帮助解释我的意思。此行为发生在模拟器和物理设备中。
原因:有人将在屏幕上签名,因此,从屏幕左侧开始将导致导航控制器弹出当前视图控制器(即返回屏幕)。
【问题讨论】:
标签: ios ipad transition segue viewcontroller
您需要使用以下代码。 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;
}
【讨论】:
手势由 UINavigationController.interactivePopGestureRecognizer 工作。您可以通过将 interactivePopGestureRecognizer.enable 设置为 NO 来禁用此行为
【讨论】:
Swift 3+
self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false
如果你不知道视图是否有导航控制器,你会想要打开它。
if self.navigationController?.interactivePopGestureRecognizer?.isEnabled != nil {
self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false
}
【讨论】: