在 viewdidload 中以编程方式设置方向不起作用 [英] programmatically setting orientation in viewdidload is not working
问题描述
我为 ipad 创建了一个应用程序,其中主屏幕应仅以纵向模式显示.所以我在 viewdidload 中使用了以下代码.
I have created an app for ipad in which the homescreen should be displayed only in portrait mode. So i have used the below code in viewdidload.
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
但它不起作用.我正在使用带有 xcode 5 的 ios 7.如果我从横向模式打开我的应用程序,它应该会自动转到纵向模式.但我是这样的:
but it is not working. I am using ios 7 with xcode 5. If i open my app from landscape mode it shouuld automatically turn to portrait mode. but i am getting like this:
但它应该是这样的:
谁能帮我解决这个问题.提前致谢.
can any one help me to solve this issue. Thanks in advance.
推荐答案
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
此方法已弃用.你不能再使用这种方法了.
This method is deprecated. You cannot use this method anymore.
https://stackoverflow.com/a/12813644/1405008
以上链接详细介绍了如何为 UIViewController
提供仅纵向模式.
Above link gives detail on how to provide portrait only mode for UIViewController
.
如果你推送到 NavigationViewController
然后试试这个.
If you pushed into NavigationViewController
then try this.
https://stackoverflow.com/a/16152506/1405008
这篇关于在 viewdidload 中以编程方式设置方向不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!