2013-11-27 23 views
3

有沒有人知道如何防止視圖控制器從屏幕的最左端從左向右滑動而被解散(或從NavigationController堆棧中彈出)?如何禁用ViewController解除從左到右的滑動?

我已經上傳了一段視頻來幫助解釋我的意思。這種行爲發生在模擬器和物理設備中。

http://youtu.be/fyNEDT140TQ

原因:有人將簽署屏幕,因此,從屏幕的左邊開始將導致navigationcontroller彈出當前視圖控制器(即返回一個屏幕)。

回答

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; 
} 
+0

讚賞。謝謝。 –

+0

歡迎光臨。享受編碼 – manujmv

1

的姿勢被UINavigationController.interactivePopGestureRecognizer工作。您可以通過設置interactivePopGestureRecognizer.enable禁用此行爲NO

0

斯威夫特3+

self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false 

你要解開它,如果你不知道該視圖將有一個導航控制器。

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