在测试我的应用程序在iOS 8上时,我发现绕过视图控制器的初始化和呈现非常缓慢。
我曾经在iOS 6和7上使用类似于以下代码的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
....
[self.window setRootViewController:_rootController];
[self.window makeKeyAndVisible];
// Conditions
if (#first launch condition#) {
// quite small controller containing Welcome showcase
WelcomeViewController *w = ....
[_rootViewController presentViewController:w animated:NO];
}
else if (#last opened item condition#) {
// pretty big container, root view controller contains
// a grid view which opens Item detail container the same way
ItemDetailController *item = ....
[_rootViewController presentViewController:item animated:NO];
}
}
这在 iOS 8 上变得非常缓慢。根视图控制器现在出现可见,但会立即重新绘制屏幕以显示呈现的内容,这需要0.5-1秒的时间。此外,演示速度的缓慢导致出现“Unbalanced calls to begin/end appearance transitions _rootViewController”警告。
最初的快速提示是将调用两个条件的函数移动到另一个函数中,并使用零延迟调用它,以便在下一个主运行循环中处理:
[self performSelector:@selector(postAppFinishedPresentation) withObject:nil afterDelay:0];
或者类似的东西。这解决了不平衡的调用问题,但是视觉间隙(根视图控制器、间隙、呈现的视图控制器)变得更大了(显然)。
当你调用像这样的常规内容时,演示的缓慢也很明显:
// Example: Delegate caught finished Sign In dialog,
// dismiss it and instantly switch to Profile controller
-(void)signInViewControllerDidFinishedSuccessfully
{
[self dismissViewControllerAnimated:NO completion:^{
UserProfileViewController *userProfile = ...
[self presentViewController:userProfile animated:NO];
}];
}
应该有一段完全公平的代码,用于在iOS 7上执行无显式闪烁的直接转换。现在,同样的事情 - 即使没有动画处理,父级在过渡期间也会闪烁。有人遇到这个问题吗?有解决方案吗?我希望能够解决这个问题,而不需要对我需要无缝转换的每个东西都进行一些有趣的魔法操作,例如UIWindow。
viewDidAppear
中吗(并添加一些逻辑以防止它们多次呈现)? - James Chen