【发布时间】:2011-07-17 09:58:04
【问题描述】:
我的应用程序以纵向模式运行,但我只想在横向模式下显示一个屏幕,因为它是一个图表。我应该在我的 uiviewcontroller 中添加什么来强制它进入横向模式?
【问题讨论】:
-
在 iOS 7 上试试这个:stackoverflow.com/questions/22491786/…
标签: iphone objective-c uiviewcontroller orientation
我的应用程序以纵向模式运行,但我只想在横向模式下显示一个屏幕,因为它是一个图表。我应该在我的 uiviewcontroller 中添加什么来强制它进入横向模式?
【问题讨论】:
标签: iphone objective-c uiviewcontroller orientation
很抱歉,这个答案会很短:如果您使用的是 UINavigationController,则不能。因此@jer 给出的答案是不正确的。 Apple 文档指出:
您的 UITabBarController 或 UINavigationController 中的所有子视图控制器不同意共同的方向集。
我最近在赏金上回答了这个问题,但我的应用在此过程中被拒绝了。在这里阅读:How to constrain autorotation to a single orientation for some views, while allowing all orientations on others?
您唯一的解决方案是扔掉 UINavigationController 并用您自己的东西重写它。
【讨论】:
通过模态显示和关闭视图控制器,您可以强制定向。将动画设置为“否”,您可以在用户甚至没有意识到它发生的情况下执行此操作。
您可以在Is there a documented way to set the iPhone orientation? 上阅读更多关于 Josh 的回答
我认为这有点像 hack,但我已经成功地实现了使用此前提强制任何设备方向的代码。
【讨论】:
您实现shouldAutorotateToInterfaceOrientation: 并让它只为UIInterfaceOrientationIsLandscape(param) 返回YES,其中param 是您为该方法声明的参数。
这将支持横向左侧和横向右侧,而不是将您锁定在一个横向方向。
【讨论】: