2011-10-26 35 views
4

我正在處理照片視圖控制器,以便在縱向和橫向視圖中顯示一些照片。我所做的是用下面的代碼編輯-(BOOL)shouldAutorotateToInterfaceOrientation方向,但在xcode中進行測試時(菜單硬件>向右旋轉),視圖不會橫向旋轉。我做了什麼不對?任何想法爲什麼這個觀點不旋轉?

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 

視圖控制器是基於標籤的iPhone應用程序的一部分,這個視圖不是根視圖:這是問題嗎?

+0

[請不要簽署您的帖子!](http://stackoverflow.com/faq#signatures) – cmbuckley

回答

0

您想覆蓋的方法是shouldAutorotateToInterfaceOrientation。您的方法簽名最後缺少Orientation

+0

我讀了你的答案10次,我不知道你想說什麼? – GeneCode

+0

@Rocotilos:檢查這個問題的編輯歷史。 OP最初有'shouldAutorotateToInterface',沒有必要的「方向」在最後。我回答後,OP編輯了這個問題,以便我的答案現在沒有意義。 – MusiGenesis

+0

啊。好的謝謝澄清。 – GeneCode

1

另請檢查您支持的方向。對於XCode 4(項目 - >摘要(選項卡) - >支持的設備方向 - >期望的方向)。

+0

已勾選景觀方向已被選中 – Steve

1

我的第一個想法只是return true;,以確保沒有任何問題與傳遞參數/你的比較(它看起來不錯,但我永遠不知道)。

接下來會是,如果此視圖不直接附加到窗口(或其他頂級對象,如果您使用的是xib),則您可能還必須在任何父視圖中返回true。爲了測試的目的,你可能只是想覆蓋:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIIinterfaceOrientation)interfaceOrientation 
{ 
    return true; 
} 

樹中的所有視圖(控制器)。

+0

已完成,但仍無法正常工作 – Steve

0

確保您在其中實現此方法的ViewController是窗口的rootViewController。 此外,使用return (interfaceOrientation != UIIinterfaceOrientationPortraitUpsideDown)更好閱讀。 ;)

-shouldAutorotateToInterfaceOrientation會被調用嗎?嘗試登錄該方法的東西...

+0

要添加nslog以進行檢查 – Steve

0

你找錯了地方:在你的RootViewController.m文件中查找以下代碼:

#elif GAME_AUTOROTATION == kGameAutorotationUIViewController 
// 
//lots of useless comments 
// 
return (UIInterfaceOrientationIsPortrait(interfaceOrientation)); //THIS LINE HERE 

是回說行(UIInterface ...人像)是決定你的應用旋轉能力的線。你可以改變這一切,讓你能夠完全旋轉,保持在一定的方向,或任何你想要的......

也是在這個

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIIinterfaceOrientation)interfaceOrientation 
    { 
     /* return (interfaceOrientation == UIIinterfaceOrientationPortrait || interfaceOrientation == UIIinterfaceOrientationLandscapeLeft || interfaceOrientation == UIIinterfaceOrientationLandscapeRight); */ //GET RID OF ALL THIS CRAP 
return true; //do this instead, and if this doesn't work, try return YES; 
} 
+0

您需要再次查看您的編程課程!此表達式返回(interfaceOrientation == UIIinterfaceOrientationPortrait || interfaceOrientation == UIIinterfaceOrientationLandscapeLeft || interfaceOrientation == UIIinterfaceOrientationLandscapeRight);是正確的 – Steve

+0

我知道這是事實,它是正確的。僅僅因爲某件事是正確的並不意味着它是有效的 – Gabe

+0

好吧你是對的:) Thx爲你的貢獻 – Steve

1

這可能只是一個錯字,但它不是UIIinterfaceOrientation,其UIInterfaceOrientation

0

我不知道這是一個錯誤類型或版本的差異,在我最新的Xcode的方法是這樣的:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)TOI nterfaceOrientation

它運作良好,您是否錯過了參數的「to」?

相關問題