修复视图控制器的方向
我的 RootViewController 中有一个按钮...... 当我单击此按钮时,它将导航到其他视图控制器。 但我希望当我单击按钮时 otherViewController 的方向应该是横向 &当我从这个页面(otherViewController)返回时,我应该再次获得纵向模式。
非常感谢您的帮助。 请帮助我,我是 iPhone 新手,所以无法处理这个问题。
I have a button in my RootViewController ....
when i click on this button it will navigate to some otherViewController.
but i want that when i click on the Button otherViewController's Orientation should be Landscape
& when i back from this page(otherViewController) i should got again Portrait mode.
lots of Thanks for any help.
Plz help me i m new in Iphone so can't able to handle this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请注意,iOS 6 中的
shouldAutorotateToInterfaceOrientation
为 已弃用。相反,您应该使用supportedInterfaceOrientations
并返回UIInterfaceOrientationMask
。例如:
以下是您可能返回的所有 UIInterfaceOrientationMask 选项:
您还应该考虑
preferredInterfaceOrientationForPresentation
。Note in iOS 6
shouldAutorotateToInterfaceOrientation
is deprecated. Instead you should usesupportedInterfaceOrientations
and return aUIInterfaceOrientationMask
.So for example:
Here are all the UIInterfaceOrientationMask options you might return:
You should also consider the
preferredInterfaceOrientationForPresentation
.一般来说,当用户旋转设备时,方向只能从纵向更改为横向(反之亦然)。
但是,如果您希望 RootViewController 始终以纵向方式呈现其视图,而 OtherViewController 始终以横向方式呈现其视图,那就很简单了。
在 RootViewController 的 .h 中:
在 OtherViewController 的 .h 中:
虽然这可能会更好,因为它允许横向左旋转和横向右旋转:
In general, orientation should only change from portrait to landscape (or vice versa) when the user rotates the device.
However, if you want your RootViewController to always present its view in portrait and your OtherViewController to always present itvs view in landscape, that's easy enough.
In your RootViewController's .h:
In your OtherViewController's .h:
Although this would probably be better as it would allow both landscape-left and landscape-right rotations:
我知道可以做到这一点的唯一方法是以模态方式呈现 otherViewController 。
在这里查看我的答案: UIViewController 加载旋转到横向但仅支持纵向
The only way I am aware this can be done is by presenting otherViewController modally.
See my answer here: UIViewController loads rotated to landscape but only supports portrait
也许有帮助。
在新视图控制器的 viewWillAppear 中添加
并在根 viewController 的 viewWillAppear 中添加
它会导致警告,但它可以工作。
Maybe it helps.
in viewWillAppear of your new view controller add
and in viewWillAppear of your root viewController add
It will cause warning but it works.