在竖屏UITabBarController/UINavigationController中显示横屏的UIViewController

4
我明白这个问题(或类似的变体)已经被问了很多次,但仍然需要找到最佳方法来解决这个问题,而不必深入使用笨拙的hack。
我有一个具有以下布局的应用程序:
UITabBarController
  ↳ UINavigationController
      ↳ PortraitViewController
          ↳ LandscapeViewController

第一个PortraitViewControllerrightBarButtonItem被设置为一个UIBarButtonItem,它调用landscapeButtonPressed:方法。该方法将LandscapeViewController推入视图控制器堆栈。
LandscapeViewController中,我在初始化期间将hidesBottomBarWhenPushed设置为YES,因为我只想让导航栏可见。
我还在loadViewviewWillAppear:中调用[UIApplication sharedApplication]上的setStatusBarOrientation:UIInterfaceOrientationLandscapeRight,然后在viewWillDisappear:中将其设置回UIInterfaceOrientationPortrait
在我的shouldAutorotateToInterfaceOrientation:实现中,我仅为UIInterfaceOrientationLandscapeRight返回YES。 PortraitViewController如下所示: 肖像视图 http://img.skitch.com/20091007-18ur7p3iubkrb1if5cak8wdxkb.png LandscapeViewController如下所示: 损坏的横向视图 http://img.skitch.com/20091007-f3ki1ga5m4ytkyg3wgwektp86e.png 正如您所看到的,视图没有正确旋转。如果在调用-[UIApplication setStatusBarOrientation:]之前调用私有方法-[UIDevice setOrientation:],我可以使导航栏正确旋转,但我不想调用私有方法,并且似乎没有办法获取我的主视图的边界来布置子视图。使用私有方法会产生以下结果: 更好的横向视图 http://img.skitch.com/20091007-8ckbx6gpbiateju9qjgew4x3k2.png 有什么解决这个问题的想法吗?
我的目标是拥有一个横向的视图,其中包含有效的横向CGRect坐标,我可以以此为基础来布置子视图。
2个回答

1

Nathan,

我觉得你已经将PortraitViewController设置为UINavigationController的rootViewController了。我也相信你在shouldAutorotateToInterfaceOrientation方法中只限制了PortraitViewController的方向为UIInterfaceOrientationPortrait。如果是这样的话,那么任何你推出的视图控制器都会有与rootViewController相同的方向,除非你不通过旋转设备来改变设备方向。

所以,如果你需要LandscapeViewController以UIInterfaceOrientationLandscapeRight方向显示,那么就在shouldAutorotateToInterfaceOrientation:方法中允许它,并不要通过显式设置设备方向来搞砸事情。


0

LandscapeViewController没有自动旋转,因为interfaceOrientationUIInterfaceOrientationLandscapeRight,所以你必须返回UIInterfaceOrientationLandscapeRight的YES。

为了使你的视图正确地调整大小,你必须使用Interface Builder打开你的xib文件,然后进入Inspector,最后进入“Size”选项卡。


正如我在问题中所说的,在横向控制器中,我已经返回了 YES - Nathan de Vries
我确信你写的是 UIInterfaceOrientationLandscapeLeft 而不是 UIInterfaceOrientationLandscapeRight ... 是我的错误。 - Marcio

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接