2009-10-07 64 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:方法中允许使用此方法,并且不要通过明确设置设备方向来解决问题。

相关问题