2012-04-05 147 views
3

我正在開發的iPhone應用程序中有一個奇怪的問題。我希望我的應用程序僅支持縱向模式,但由於某種原因,我無法執行此操作(設備&模擬器)。如何僅在iPhone應用程序上支持肖像模式

只支持縱向模式我做了如下:

  • 在上Xcode中TARGET摘要部分,我只選擇了肖像。
  • 我所有的ViewControllers實現shouldAutorotateToInterfaceOrientation

但正如我所說,它不會工作,而奇怪的結果是,應用程序的支持ALL的方向(縱向,上下顛倒,景觀左,右景觀) 。
任何想法?

這個我如何實現shouldAutorotateToInterfaceOrientation

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    NSLog(@"Checking orientation %d", interfaceOrientation); 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

我注意到剛纔,當我旋轉手機,我得到這個消息:

「兩級旋轉動畫被棄用此應用程序應該 使用更流暢的單段動畫。「

這是什麼意思?

+0

從每個地方返回NO。 – Nilesh 2012-04-05 18:13:17

+0

試試我的答案。也許它會有所幫助。 – 2012-04-06 10:45:15

+0

試着在你的'shouldAutorotateToInterfaceOrientation'方法中添加'NSLog(@「檢查方向%d」,interfaceOrientation);''。當您旋轉模擬器或您的設備時是否調用了它們中的任何一個? – Dondragmer 2012-04-07 22:48:42

回答

3

它可以在屏幕上有多個ViewControllers。 UITabBarController本身就是一個UIViewController,如果它選擇的話,它只傳遞shouldAutorotateToInterfaceOrientation:請求給viewControllers。默認實現是這樣做的,但是如果你繼承它的話,XCode生成的代碼(從iOS 5.1開始)不會。

9

在目標摘要上僅選擇肖像。

+1

正如我寫的,我已經這樣做:( – Eyal 2012-04-05 16:40:28

+0

嘗試刪除shouldAutorotateToInterfaceOrientation方法,並保持目標設置正確。 – Eric 2012-04-05 16:43:19

+0

抱歉不起作用 – Eyal 2012-04-05 16:53:03

1

檢查你的plist並確保鑰匙設置正確。

+0

我檢查,它被設置爲肖像... – Eyal 2012-04-05 16:41:21

3

轉到info.plist文件。右鍵單擊打開它作爲源代碼。並尋找這條線。對我來說,在iPad上它是這樣的:

<key>UISupportedInterfaceOrientations~ipad</key> 

刪除所有其它的方向,並保持你need..Like這個只有一個:

<array> 

    <string> UIInterfaceOrientationPortrait </string> 

</array> 
+0

謝謝,但我已經做到了 – Eyal 2012-04-06 10:47:33

+0

然後你的問題很奇怪。 – 2012-04-06 10:48:08

相關問題