2011-06-07 25 views
3

我試圖提出一個模態的UITabBarController使用下面的代碼:呈現的UITabBarController模態 - 自動旋轉問題

// Declare all view controllers. 
TabOne *tabOne = [[TabOne alloc] initWithNibName:@"TabOne" bundle:nil]; 
TabTwo *tabTwo = [[TabTwo alloc] init]; 
TabThree *tabThree = [[TabThree alloc] init]; 

// Set each view controller's delegate to self. 
tabOne.delegate = self; 
tabTwo.delegate = self; 
tabThree.delegate = self; 

// Set a title for each view controller. 
tabOne.title = @"One"; 
tabTwo.title = @"Two"; 
tabThree.title = @"Three"; 

// Create a tab bar controller. 
UITabBarController *tabBarController = [[UITabBarController alloc] init]; 
[tabBarController setViewControllers:[NSArray arrayWithObjects:tabOne,tabTwo,tabThree, nil]]; 

// Present the tab bar controller modally. 
[self presentModalViewController:tabBarController animated:NO]; 

// Memory management. 
[tabOne release]; 
[tabTwo release]; 
[tabThree release]; 

這種預期只是我在控制檯中下列警告所有作品:

使用兩段旋轉動畫。要使用更平滑的單級動畫,此應用程序必須移除兩階段方法實現。 旋轉多個視圖控制器或視圖控制器而不是窗口委託時,不支持使用兩級旋轉動畫。

我做了一些研究這一點,並檢查了shouldAutorotateToInterfaceOrientation執行如下:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

據我所知道的,問題是標籤欄控制器不是根視圖控制器,但我將這種模式視圖以某種方式呈現在深層視圖層次結構中。它是從另一個模式視圖調用的,該視圖本身是從應用程序委託中設置的選項卡中調用的。

我知道這是一個古老的板栗,但它讓我難倒了。有什麼想法嗎?

在此先感謝。

+1

你應該檢查Ax Monkey的正確答案。 – Alexander 2012-07-02 10:20:47

回答

6

我有類似的問題。

UITabBarController的方向處理有一些奇怪的行爲。在設置其方向時,它會遞歸調用self.selectedViewController以決定是使用單級還是雙級動畫。這似乎是明智的,但麻煩是self.selectedViewController最初爲零(特別是,如果你第一次模態地顯示UITabBarController),並且可能會混淆控制器。取決於iOS版本,一個無選擇的視圖控制器將導致UITabBarController相信不支持單級動畫。

試試這個:當你第一次加載/初始化的UITabBarController,添加行

tabBarController.selectedIndex = 0; 

我得到這樣的警告(包括嚴重的視力問題:視圖控制器被切換方向,但在狀態欄是不是) ,並通過這種方式設置索引解決了問題。 UITabBarController成功調用到其選定的視圖控制器中,並檢測到單級動畫。

+1

你對!非常感謝,它解決了我的問題。 (我沒有視覺問題,但警告很煩人)。 – Alexander 2012-07-02 10:24:25

+0

不那麼深,但官方解釋是[這裏](http://stackoverflow.com/questions/6636683/how-to-eliminate-two-stage-rotation-warning) – Alexander 2012-07-02 10:32:18

+0

我正在尋找這個解決方案的所有地方!我有着同樣瘋狂的視覺問題,但找不到任何東西;視圖控制器切換方向,但鍵盤和狀態欄沒有。這固定它!謝謝! – BFeher 2013-10-31 04:21:48