2011-04-20 61 views
2

我有一個情況,我有多個視圖通過UITabBarController控制。其中一種觀點是通過UINavigationController控制的。應用程序只能支持所有視圖的肖像...除了一個單獨的視圖。這個視圖被推到導航控制器的堆棧上,並且應該允許縱向和橫向。允許一個視圖支持多個方向,而其他人不要iPhone

我已經嘗試過所有我能想到的解決方案,但是,解決方案不工作或者更糟是完全不可預測的。

有沒有人以乾淨的方式解決這個問題?

+0

您是否嘗試過使用的UIDevice OrientationDidChangeNotification接收UIDeviceOrientation更改並做出相應反應(旋轉變換)?如果列出了所有您認爲的解決方案以及爲什麼他們不適合您(我想您確實嘗試了各種各樣的shouldAutorotateToInterfaceOrientation組合),這將有所幫助。順便提一句, – magma 2011-04-20 18:48:48

+0

- 你想旋轉的視圖由視圖控制器管理嗎?UIViews不會自行旋轉,它們的控制器旋轉它們。見:http://stackoverflow.com/questions/4324394/iphone-subview-rotation-problem – magma 2011-04-20 18:54:53

+0

@magma是的,他們在控制器。問題顯然是基於使用UITabBarController。 – MarkPowell 2011-04-20 19:04:53

回答

3

您介紹或者使用presentModalViewControllerpushViewController應該支持任何方位,使用這種方法的視圖的控制器:

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

使用這種方法,當你在橫向出示您的控制器,它會正確地顯示在景觀方向也一樣。

+0

@MarkPowell:檢查我的答案。 – Jhaliya 2011-04-20 18:51:52

+0

結束時只是將視圖重新實現爲模態視圖。與tabbarcontroller混淆最終成爲兔子洞無處可去。 – MarkPowell 2011-04-20 20:44:38

1

我有同樣的問題。您必須爲您的UITabBarController實施shouldAutorotateToInterfaceOrientation:,並且您希望在所有視圖控制器中支持的所有方向返回YES。在所有其他視圖控制器的相同方法中,僅針對您希望在每個視圖控制器中支持的方向返回YES。

要實現shouldAutorotateToInterfaceOrientation:爲您的UITabBarController,你可以繼承的UITabBarController,但一個簡單的方法是落實科學的UITabBarController一個類別,只是實現該方法:

@implementation UITabBarController(orientation) 

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toOrientation 
{ 
    return YES; // or whatever you need 
} 

@end 

注:鍵入到Web瀏覽器;未編譯。 :-)

你可以把這個權利放在你的應用代理.m文件中。

我發現的是,UITabBarController只爲肖像返回YES,這顯然也影響所有從屬視圖控制器。在我的情況下,我有一個從屬視圖控制器,我想支持縱向和橫向,這解決了它。

+0

啊,這是我的問題的核心。我創建了一個自定義的UITabBarController,並覆蓋了shouldAutorotateToInterfaceOrientation以傳遞可見視圖控制器的值。但是,如果設備處於橫向模式,仍然存在切換回另一個視圖時無法強制縱向顯示的問題。 – MarkPowell 2011-04-20 19:04:01

1

如果您有一個標籤欄內的導航,那麼唯一的選擇是將特定視圖呈現爲模式視圖(標籤欄需要所有視圖支持自動旋轉的方向)。所以基本上單一視圖控制器,需要景觀應實現

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
     if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) { 
      // Create the landscape version of the view and present it modally 
     } 

     return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

然後解僱的模態視圖控制器相同的方法模式的看法,通過檢測縱向和使用父[self.parentViewController dismissModalViewControllerAnimated: animated]

0

方法對於iOS -6,我已經這樣做了,它大大運行

(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft; 
} 

(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationLandscapeLeft; 
} 

這將幫助你....

相關問題