强制 UIViewController 仅以横向模式显示
我的应用程序以纵向模式运行,但我只想以横向模式显示一个屏幕,因为它是图表。我应该向 uiviewcontroller 添加什么以强制其仅进入横向模式?
My app runs in portrait mode, but i want to show one screen in landscape mode only as it is a chart. What do i add to my uiviewcontroller to force it into landscape mode only?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
很抱歉,这个答案会很简短:如果您使用的是 UINavigationController,则不能。因此@jer 给出的答案是不正确的。苹果文档指出:
我最近在赏金中回答了这个问题,但我的应用程序在此过程中被拒绝。请在此处阅读:如何将某些视图的自动旋转限制为单一方向,同时允许其他视图的所有方向?
唯一的解决方案你所要做的就是扔掉 UINavigationController 并用你自己的东西重写它。
I'm sorry but this answer will be very short: If you're using the UINavigationController, you can't. The answer @jer gives is therefore incorrect. The Apple documentation states:
I recently had this question answered on a bounty and my app rejected in the process. Read up on that here: How to constrain autorotation to a single orientation for some views, while allowing all orientations on others?
The only solution you have, is to throw away the UINavigationController and rewrite it with something of your own.
通过以模态方式呈现和关闭视图控制器,您可以强制确定方向。将动画设置为“NO”,您甚至可以在用户没有意识到它发生的情况下执行此操作。
您可以在阅读更多关于乔希的回答设置 iPhone 方向的记录方法?
我认为这有点黑客,但我已经成功地使用此前提实现了代码来强制任何设备方向。
By presenting and dismissing a view controller modally you can force an orientation. Set animations to "NO" and you can do this without the user even realizing it occurred.
You can read more about this Josh's answer on Is there a documented way to set the iPhone orientation?
I consider it a bit of a hack, but I've successfully implemented code using this premise to force any device orientation.
您实现
shouldAutorotateToInterfaceOrientation:
并让它仅对UIInterfaceOrientationIsLandscape(param)
返回 YES,其中param
是您为该方法声明的参数。这将支持横向左和横向右,而不是将您锁定为仅一种横向方向。
You implement
shouldAutorotateToInterfaceOrientation:
and have it return only YES forUIInterfaceOrientationIsLandscape(param)
whereparam
is the parameter you declared for the method.This will support landscape left and landscape right, instead of locking you to only one landscape orientation.