xcode 如何消除“两级轮换”警告?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6636683/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to eliminate "two-stage rotation" warning?
提问by Matt.Z
My window's rootViewController is a UINavigationController Then.. In this navigation controller's rootViewController, I popup a modal view(a UITabBarController)
我的窗口的 rootViewController 是一个 UINavigationController 然后..在这个导航控制器的 rootViewController 中,我弹出一个模态视图(一个 UITabBarController)
something like this:
像这样:
UIWindow
->UINavigationController
-->MyFirstViewController<--In this class I run following code
[self.navigationController presentModalViewController:tabController animated:YES];
Then the debugger warning :Using two-stage rotation animation is not supported when rotating more than one view controller or view controllers not the window delegate
然后调试器警告:当旋转多个视图控制器或视图控制器不是窗口委托时,不支持使用两阶段旋转动画
However, if the modal view is not tabController this warning does not appear.
但是,如果模态视图不是 tabController,则不会出现此警告。
What will this behavior do harm to the application when I popup tabController modal view in a navigation controller?
当我在导航控制器中弹出 tabController 模态视图时,这种行为会对应用程序造成什么危害?
Or I should find another way to do this?
或者我应该找到另一种方法来做到这一点?
I found several similar questions on this site, but I don't get it...
我在这个网站上发现了几个类似的问题,但我不明白......
回答by LuckyLuke
The reason is that you are using a UITabBarController outside of the intended usage of it. It is ONLY intended to be used as a root controller, and should you need something similiar to a tabbar use toolbar. I was running into trouble with the exact problem about a half year ago. You will also run into other problems if you use it like that, unfortunately.
原因是您使用的 UITabBarController 超出了它的预期用途。它仅用作根控制器,如果您需要类似于标签栏使用工具栏的东西。大约半年前,我遇到了确切问题的麻烦。不幸的是,如果你这样使用它,你也会遇到其他问题。
UITabBarController documentation
Because the UITabBarController class inherits from the UIViewController class, tab bar controllers have their own view that is accessible through the view property. When deploying a tab bar interface, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.
因为 UITabBarController 类继承自 UIViewController 类,所以标签栏控制器有自己的视图,可以通过 view 属性访问。部署标签栏界面时,必须将此视图安装为窗口的根目录。与其他视图控制器不同,标签栏界面不应作为另一个视图控制器的子项安装。
回答by Maciej Swic
This will also happen if you only add a blank UITabbarController without any child controllers, like so:
如果您只添加一个没有任何子控制器的空白 UITabbarController 也会发生这种情况,如下所示:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//Tab bar controller
UITabBarController* tabBarController = [[UITabBarController alloc] init];
[[self window] setRootViewController:tabBarController];
[self.window makeKeyAndVisible];
return YES;
}
The warning will go away if you add a child view controller to the UITabBarController before declaring it the rootViewController of your UIWindow.
如果在将子视图控制器声明为 UIWindow 的 rootViewController 之前将子视图控制器添加到 UITabBarController,警告将消失。
回答by Oliver
I got the same warning when subclassing UITabBarController but forgetting to call the base class's viewWillAppear: method in my own class.
我在继承 UITabBarController 时收到了同样的警告,但忘记在我自己的类中调用基类的 viewWillAppear: 方法。
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated] // <--- adding this fixed the warning
...
}
回答by Klaus Thul
I have an app where a UITabBarController
is the root view controller. Depending on an in-app purchase, the child view controllers are different.
我有一个应用程序,其中 aUITabBarController
是根视图控制器。根据应用内购买,子视图控制器是不同的。
In my NIB, I had the UITabBarController
without any child view controllers. I added the child view controllers in application:didFinishLaunchingWithOptions:
在我的 NIB 中,我UITabBarController
没有任何子视图控制器。我添加了子视图控制器application:didFinishLaunchingWithOptions:
This caused the warning "two-stage" rotation to appear. As soon as I added one single child view controller to the tabbar controller in the NIB it disappeared.
这导致出现警告“两阶段”轮换。一旦我向 NIB 中的选项卡栏控制器添加了一个子视图控制器,它就消失了。
回答by Diogo Hacka
@Maciej Swic's answer helped me a bit.
@Maciej Swic 的回答对我有所帮助。
In my case I had already 2 child for the UITabBarController.
就我而言,我已经为 UITabBarController 生了 2 个孩子。
For some strange reason all I need was to put
出于某种奇怪的原因,我所需要的只是把
[self.window makeKeyAndVisible];
[self.window makeKeyAndVisible];
after I added the 2 children.
在我添加了 2 个孩子之后。
回答by dave adelson
Oliver's answer did the trick for me...it was interesting, though...i had not been having any problems until i added a viewWillAppear:animated method to to the subclassed tabviewcontroller...at that point, everything went haywire, until it was fixed by adding the [super viewWillAppear:animated] statement Oliver suggests...
Oliver 的回答对我有用……虽然很有趣……我一直没有遇到任何问题,直到我向子类 tabviewcontroller 添加了一个 viewWillAppear:animated 方法……那时,一切都变得混乱,直到它是通过添加 [super viewWillAppear:animated] 语句修复的,奥利弗建议......
回答by bollhav
Had problem with Two-stage animation warning with the following order:
出现以下顺序的两阶段动画警告问题:
self.window.rootViewController = self.tabBarController;
self.tabBarController.selectedIndex = 0;
But changing the order help me to eliminate the warning.
但是更改顺序可以帮助我消除警告。
self.tabBarController.selectedIndex = 0;
self.window.rootViewController = self.tabBarController;
Hope this helps.
希望这可以帮助。