2012-02-09 166 views
1

我的应用程序被固定为横向模式,但viewDidLoad中时(),甚至viewWillAppear中(),下面的画像尺寸还是回到:如何让我的iPhone应用程序以横向模式启动?

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 

我觉得这很奇怪。 为什么会发生这种情况!?我该如何解决这个问题?

+2

你在你的根返回YES UIViewController的 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation方法? – 2012-02-09 23:35:21

+0

我使用:return(interfaceOrientation == UIInterfaceOrientationLandscapeLeft);.我可以找到的每个配置都设置为横向。仍然没有改变。我怀疑它是iOS中的一个“功能”错误。 – 2012-02-10 02:54:18

+0

我刚回去阅读Apple文档。 viewWillAppear:在任何动画配置为显示视图之前调用“。由于旋转是(可以)动画,这可能是为什么你看到未旋转的尺寸。所以我怀疑你是对的 - 这是一个“功能” – 2012-02-10 16:45:13

回答

3

在你的应用程序的Info.plist文件,指定密钥:

UISupportedInterfaceOrientations 

与景观价值左,右:

enter image description here

编辑

原始plist代码应该如下所示:

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

编辑2

您还需要这把钥匙这就决定了状态栏的初始取向:

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

此外,你需要确保ALL您的视图控制器(标签栏,导航栏,常规视图控制器)工具

shouldAutorotateToInterfaceOrientation 

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

下面是关于这个问题的苹果文档的文章:

Technical Note TN2244

最后,这里有一些其他有关这个主题的SO职位: post 1post 2.

+0

已经有了。 UIInterfaceOrientationLandscapeLeft 2012-02-09 23:33:16

+0

@SebastianDwornik请参阅编辑。 – Rayfleck 2012-02-09 23:37:17

+0

是的,我明白了。我说这没什么区别。你的代码是否按照应有的方式工作? – 2012-02-10 02:52:48

相关问题