我明白这个问题(或它的变体)已被问了好几次,但它仍然是如何最好地解决这个问题,而不深入到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