2011-06-07 26 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