2009-10-07 44 views
4

我明白這個問題(或它的變體)已被問了好幾次,但它仍然是如何最好地解決這個問題,而不深入到kludgy黑客。在畫像中顯示一個橫向UIViewController UITabBarController/UINavigationController

我有以下佈局的應用程序:

UITabBarController 
    ↳ UINavigationController 
     ↳ PortraitViewController 
      ↳ LandscapeViewController 

第一PortraitViewControllerrightBarButtonItem集到UIBarButtonItem,它調用landscapeButtonPressed:。該方法將LandscapeViewController推到視圖控制器堆棧上。

LandscapeViewController中,我在初始化過程中將hidesBottomBarWhenPushed設置爲YES,因爲我只希望導航欄可見。

我還呼籲[UIApplication sharedApplication]setStatusBarOrientation:UIInterfaceOrientationLandscapeRightloadViewviewWillAppear:,然後將其放回至UIInterfaceOrientationPortraitviewWillDisappear:

在我的shouldAutorotateToInterfaceOrientation:實現中,我僅返回YES,僅用於UIInterfaceOrientationLandscapeRight

PortraitViewController看起來是這樣的:

Portrait View http://img.skitch.com/20091007-18ur7p3iubkrb1if5cak8wdxkb.png

LandscapeViewController看起來是這樣的:

Broken Landscape View http://img.skitch.com/20091007-f3ki1ga5m4ytkyg3wgwektp86e.png

正如你所看到的,視圖不旋轉正確。如果我在撥打-[UIApplication setStatusBarOrientation:]之前撥打私人電話號碼-[UIDevice setOrientation:],我可以讓導航欄正確旋轉,但我寧願不要調用私有方法,也不會有辦法獲取我的主視圖的邊界用於佈置子視圖。使用這個私有方法的結果:

Better Landscape View http://img.skitch.com/20091007-8ckbx6gpbiateju9qjgew4x3k2.png

如何解決這個問題的任何想法?

我的目標是有一個橫向的視圖,有效的景觀CGRect座標,我可以用它作爲佈局子視圖的基礎。

回答

0

的LandscapeViewController不會自動旋轉,因爲interfaceOrientationUIInterfaceOrientationLandscapeRight,所以你必須返回YES爲UIInterfaceOrientationLandscapeRight

爲了使您的意見調整正確,你必須打開與Interface Builder中的廈門國際銀行文件,然後進入檢查,最後進入標籤「大小」。

+0

正如我在問題中所說的,我已經在景觀控制器中返回了YES。 – 2009-10-09 02:38:16

+0

我確定你已經寫了'UIInterfaceOrientationLandscapeLeft'而不是'UIInterfaceOrientationLandscapeRight' ... 我的錯誤。 – Marcio 2009-10-09 11:41:45

1

彌敦道,

我覺得你已經設置PortraitViewController爲的UINavigationController的RootViewController的。我也相信你只是將PortraitViewController的方向限制爲僅在shouldAutorotateToInterfaceOrientation方法中的UIInterfaceOrientationPortrait。如果是這樣,除非您沒有通過旋轉設備來更改設備方向,否則您推送的任何視圖控制器都將具有rootViewController本身的方向。

因此,如果您需要UIInterfaceOrientationLandscapeRight方向的LandscapeViewController,那麼只需在shouldAutorotateToInterfaceOrientation:方法中允許使用此方法,並且不要通過明確設置設備方向來解決問題。

相關問題