以模态方式呈现UITabBarController - 自动旋转问题 [英] Presenting UITabBarController Modally - Autorotate Problem

查看:102
本文介绍了以模态方式呈现UITabBarController - 自动旋转问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码以模态方式呈现UITabBarController:

I'm attempting to present a UITabBarController modally using the following code:

// 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];

这一切都按预期工作,只是我在控制台中收到以下警告:

This all works as expected except that I get the following warnings in the console:


使用两阶段旋转动画。要使用更平滑的单阶段动画,此应用程序必须删除两阶段方法实现。
当旋转多个视图控制器或视图控制器而不是窗口委托时,不支持使用两阶段旋转动画。

Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations. Using two-stage rotation animation is not supported when rotating more than one view controller or view controllers not the window delegate.

我已经对此做了一些研究,并检查了shouldAutorotateToInterfaceOrientation如下实现:

I've done some research on this and have checked that shouldAutorotateToInterfaceOrientation is implemented as follows:

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

据我所知,问题是标签栏控制器是不是根视图控制器,但我将这种模态视图以某种方式呈现在深视图层次结构中。它是从另一个模态视图中调用的,它本身是从应用程序委托中设置的标签栏调用的。

As far as I can tell, the problem is that the tab bar controller is not the root view controller, but I'm presenting this modal view some way into a deep view hierarchy. It's called from another modal view, which itself is called from a tab bar set in the application delegate.

我知道这有点像一个老板栗,但它有我很难过。有什么想法?

I know this is a bit of an old chestnut, but it's got me stumped. Any thoughts?

提前致谢。

推荐答案

我是有一个类似的问题。

I've had a similar problem.

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

UITabBarController has some odd behavior with its orientation handling. When setting its orientation, it calls recursively into self.selectedViewController to decide whether to use one-stage or two-stage animation. That seems sensible, but the trouble is self.selectedViewController is initially nil (in particular, if you're displaying the UITabBarController modally for the first time), and that can confuse the controller. Depending on the iOS version, a nil selectedViewController will lead the UITabBarController to believe that one-stage animation is unsupported.

试试这个:当你第一次加载/初始化你的UITabBarController时,添加行

Try this: when you first load / initialize your UITabBarController, add the line

tabBarController.selectedIndex = 0;

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

I was getting this warning (including serious visual problems: the view controller was switching orientation but the status bar was not), and setting the index this way fixed the problem. The UITabBarController successfully called into its selected view controller, and detected the one-stage animation.

这篇关于以模态方式呈现UITabBarController - 自动旋转问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆