1

我有一個使用基本選項卡欄模板創建的iPad選項卡欄應用程序。我添加了一些自定義視圖控制器(每個選項卡一個,每個都帶有一個相應的NIB),還有一些額外的視圖控制器,並將NIB用作模態視圖。一切都很好,直到我旋轉設備。爲什麼我的視圖不會旋轉?

我的應用程序只支持縱向,所以我有這個在我所有的視圖控制器:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation != UIDeviceOrientationLandscapeLeft) && 
    (interfaceOrientation != UIDeviceOrientationLandscapeRight); 
} 

但是,應用程序不會在模擬器或設備時天翻地覆旋轉。我加倍和三倍檢查,我所有的視圖控制器有上述代碼。

我瀏覽了所有的NIB,並檢查了他們都有「旋轉子視圖」打勾。無論如何,我還沒有更改任何NIB設置的默認設置,除了讓它們在選項卡視圖中顯示所需的基本功能之外。

我想在我所有的視圖控制器代碼更改爲此:

- (BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)interfaceOrientation 
{ 
    return UIInterfaceOrientationIsPortrait(interfaceOrientation); 
} 

它沒有什麼區別。我已經絕對確信所有視圖控制器都使用了相同的方法。我不知道我還能做什麼。我看不出爲什麼它不應該旋轉到顛倒視圖。

任何幫助,這將不勝感激。

回答

1

Got it!我的一個視圖控制器沒有連接到IB的相關選項卡。由於我沒有添加圖像或爲該視圖控制器編寫代碼,我沒有注意到它在IB中沒有關聯。我做了完成了shouldAutorotateToInterfaceOrientation方法,但似乎直到在IB中建立連接才生效。

非常感謝您對此提出的建議。這是一個非常令人沮喪的問題,現在處理!

0

「您所有的視圖控制器」是否包含Tab Bar Controller?

在標籤欄應用程序中,唯一的視圖控制器是shouldAutoRotateToInterfaceOrientation被調用和評估。

+0

謝謝。事情是,我沒有一個單獨的標籤欄控制器。我在IB中使用MainWindow.xib,但沒有實現文件。那麼,我將如何設置該控制器的shouldAutoRotateToInterfaceOrientation? – beev

+1

好吧,創建它。即使它唯一實現的方法是shouldAutoRotateToInterfaceOrientiation。 –

+0

如果你在IB有它,你分配了什麼課程?默認值是UITabBarController。這意味着有一個。你只是沒有繼承它,並沒有使用你自己的標籤欄控制器。根據您的數據結構,您也可能希望在標籤欄控制器中實現didReceiveMemoryWarning。 –

0

你擁有的第一個片段是邏輯上不正確:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation 
{ 
    return (orientation != UIDeviceOrientationLandscapeLeft) && 
      (orientation != UIDeviceOrientationLandscapeRight); 
} 

這裏,orientationUIInterfaceOrientationUIDeviceOrientationLandscapeLeftUIDeviceOrientation實例的實例。這兩種不是同一類型,所以不應該進行比較。

相反,你應該使用UIInterfaceOrientation選項:

typedef enum { 
    UIInterfaceOrientationPortrait   = UIDeviceOrientationPortrait, 
    UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, 
    UIInterfaceOrientationLandscapeLeft  = UIDeviceOrientationLandscapeLeft, 
    UIInterfaceOrientationLandscapeRight  = UIDeviceOrientationLandscapeRight 
} UIInterfaceOrientation; 

更改方法

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

(放時肯定的,而不是消極的代碼似乎對我來說更可讀)

+0

對不起,我設法在第一個例子的問題中粘貼錯誤的代碼。我現在已經改變它來反映我的代碼中實際存在的內容。我嘗試將其改爲您所建議的內容,我希望這會使其僅使用風景方向,但仍然以縱向啓動,並且不會旋轉。這很奇怪,因爲我有幾個其他應用程序使用完全相同的代碼,並且它們正確旋轉。 – beev