首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在纵向UITabBarController/UINavigationController中显示横向UIViewController

在纵向UITabBarController/UINavigationController中显示横向UIViewController
EN

Stack Overflow用户
提问于 2009-10-07 08:34:46
回答 2查看 1.7K关注 0票数 4

我知道这个问题(或它的变体)已经被问了好几次了,但它仍然是如何最好地处理这个问题,而不是钻研杂乱无章的黑客。

我有一个具有以下布局的应用程序:

代码语言:javascript
运行
复制
UITabBarController
  ↳ UINavigationController
      ↳ PortraitViewController
          ↳ LandscapeViewController

第一个PortraitViewController将其rightBarButtonItem设置为一个调用landscapeButtonPressed:UIBarButtonItem。该方法将LandscapeViewController推送到视图控制器堆栈上。

LandscapeViewController中,我在初始化期间将hidesBottomBarWhenPushed设置为YES,因为我只希望导航栏可见。

我还在loadViewviewWillAppear:中的[UIApplication sharedApplication]上调用setStatusBarOrientation:UIInterfaceOrientationLandscapeRight,然后在viewWillDisappear:中将其设置回UIInterfaceOrientationPortrait

在我的shouldAutorotateToInterfaceOrientation:实现中,我只为UIInterfaceOrientationLandscapeRight返回YES。

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坐标的横向视图,我可以将其用作布局子视图的基础。

EN

Stack Overflow用户

发布于 2009-10-09 19:19:18

内森

我觉得你已经把PortraitViewController设置为UINavigationController的rootViewController了。我还相信您在shouldAutorotateToInterfaceOrientation方法中将PortraitViewController的方向限制为仅UIInterfaceOrientationPortrait。如果是这样,则您推送的任何视图控制器都将具有rootViewController本身的方向,除非您不是通过旋转设备来更改设备方向。

因此,如果您需要在UIInterfaceOrientationLandscapeRight方向上使用LandscapeViewController,那么只需要在shouldAutorotateToInterfaceOrientation: method中允许这样做,并且不要通过显式设置设备方向来搞砸事情。

票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1530298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档