我明白這個問題(或它的變體)已被問了好幾次,但它仍然是如何最好地解決這個問題,而不深入到kludgy黑客。在畫像中顯示一個橫向UIViewController UITabBarController/UINavigationController
我有以下佈局的應用程序:
UITabBarController
↳ UINavigationController
↳ PortraitViewController
↳ LandscapeViewController
第一PortraitViewController
有rightBarButtonItem
集到UIBarButtonItem
,它調用landscapeButtonPressed:
。該方法將LandscapeViewController
推到視圖控制器堆棧上。
在LandscapeViewController
中,我在初始化過程中將hidesBottomBarWhenPushed
設置爲YES
,因爲我只希望導航欄可見。
我還呼籲[UIApplication sharedApplication]
setStatusBarOrientation:UIInterfaceOrientationLandscapeRight
在loadView
和viewWillAppear:
,然後將其放回至UIInterfaceOrientationPortrait
在viewWillDisappear:
。
在我的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座標,我可以用它作爲佈局子視圖的基礎。
正如我在問題中所說的,我已經在景觀控制器中返回了YES。 – 2009-10-09 02:38:16
我確定你已經寫了'UIInterfaceOrientationLandscapeLeft'而不是'UIInterfaceOrientationLandscapeRight' ... 我的錯誤。 – Marcio 2009-10-09 11:41:45