2012-02-09 160 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

相關問題