1

我的应用程序固定为横向模式,但在 viewDidLoad() 甚至 viewWillAppear() 期间,仍会返回以下纵向尺寸:

self.view.bounds.size.width = 320.00
self.view.bounds.size.height = 480.00

直到 viewDidAppear() 才产生实际的景观尺寸。

self.view.bounds.size.width = 480.00
self.view.bounds.size.height = 320.00

我觉得这很奇怪。为什么会这样!?我该如何解决这个问题?

4

1 回答 1

3

在您应用的 info.plist 文件中,指定密钥:

 UISupportedInterfaceOrientations

左右横向的值:

在此处输入图像描述

编辑

原始 plist 代码应如下所示:

    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>

编辑 2

您还需要此键来确定状态栏的初始方向:

 <key>UIInterfaceOrientation</key>
 <string>UIInterfaceOrientationLandscapeRight</string>

此外,您需要确保所有视图控制器(标签栏、导航栏、常规视图控制器)都实现

 shouldAutorotateToInterfaceOrientation

并返回一个横向(左或右)值。

这是有关该主题的 Apple 文档文章:

技术说明 TN2244

最后,这里有一些关于这个主题的其他 SO 帖子: 帖子 1帖子 2。

于 2012-02-09T23:30:25.297 回答