2011-11-25 50 views
0

我已經有了這樣的View層次結構。在TabbarController的NavigationController中強制UIViewController旋轉

UITabBarController 
    | 
    UINavigationController 
    | | 
    | UIViewController 
    | 
    UINavigationController 
     | 
     UIViewController 

的事情是,我有一個只能在肖像顯示一個視圖控制器,只要我打開設備到另一個景觀視圖控制器被放在上面推,即工作作爲迄今預期。

我現在想的是,只要我推在新彈出的ViewController後退按鈕,舊的ViewController被強制人像,即使設備仍處於風景。
我已經嘗試過渡,但隨後其他視圖被搞砸了,不能正確識別那裏的方向,導致混亂的流離失所的意見。

回答

2

只爲我工作的事情,用

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 

在我的ViewController與presentModalViewController呈現它。 這會強制View保持風景。 不完全是我想要的,但它解決了。下面

1

嘗試添加該原始視圖控制器:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) return YES; 
    return NO; 
} 

這應該迫使它只能以縱向顯示。

+0

可悲的是,這也不工作。由於設備已處於橫向模式,因此它可能會認爲:「好吧,我會保持原樣。」出現這種情況的唯一的事情是,這兩種觀點之間的過渡動​​畫是錯誤的(從上到下而不是從右至左) – muffe

+0

你可能是對的,我只曾經與一個模式視圖控制器使用此。 –

1

該代碼將迫使視圖到風景模式,但僅當父視圖控制器支持橫向模式。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 

如果你想強行進入橫向模式視圖的父視圖控制器只有肖像,你必須創建一個新的新的導航控制器。最簡單的方法是在模態視圖中顯示強制橫向視圖控制器。因此,使用presentModalViewController而不是pushViewController。

相關問題