Ios4 自动旋转问题

Ios4 自动旋转问题,ios4,uitabbarcontroller,modal-dialog,Ios4,Uitabbarcontroller,Modal Dialog,我试图使用以下代码以模态方式呈现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 contr

我试图使用以下代码以模态方式呈现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);
}
就我所知,问题在于选项卡栏控制器不是根视图控制器,但我以某种方式将此模式视图呈现到深度视图层次结构中。它是从另一个模态视图调用的,该视图本身是从应用程序委托中设置的选项卡栏调用的

我知道这有点老掉牙,但这让我很为难。有什么想法吗


提前谢谢。

我也遇到过类似的问题

UITabBarController的方向处理有一些奇怪的行为。设置其方向时,它会递归调用self.selectedViewController以决定是使用单阶段动画还是两阶段动画。这似乎是合理的,但问题是self.selectedViewController最初为零(特别是,如果您第一次以模态方式显示UITabBarController),这可能会混淆控制器。根据iOS版本的不同,nil selectedViewController将使UITabBarController认为不支持单阶段动画

尝试以下操作:当您第一次加载/初始化UITabBarController时,添加行

tabBarController.selectedIndex = 0;

我收到了这个警告(包括严重的视觉问题:视图控制器正在切换方向,但状态栏没有),通过这种方式设置索引解决了这个问题。UITabBarController成功调用其选定的视图控制器,并检测到单阶段动画。

您应该检查Axe Monkey的正确答案。您说得对!非常感谢,它解决了我的问题。(我没有视觉上的问题,但警告很烦人)。没有那么深,但官方解释是我到处寻找这个解决方案!我也有同样疯狂的视觉问题,但找不到任何东西;视图控制器切换了方向,但键盘和状态栏没有切换。这个修好了!谢谢