iOS 8 – 在设置关键窗口或关闭并立即呈现另一个 View Controller 后快速呈现 View Controller 时出现故障

标签 ios uiviewcontroller presentviewcontroller

自从在 iOS 8 上测试我的应用程序后,我发现围绕 View Controller 初始化和呈现的工作非常慢。

我曾经在 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 中,这变成了一个非常缓慢的 hell 。 Root View Controller 现在显示 0.5-1 秒,然后立即重新绘制屏幕。此外,呈现的缓慢开始导致 Unbalanced calls to begin/end appearance transitions _rootViewController 警告。

最初的快速提示是通过调用另一个函数来移动两个条件,并以零延迟调用它,以便在下一个主运行循环中处理它:

[self performSelector:@selector(postAppFinishedPresentation) withObject:nil afterDelay:0];

或类似的东西。这解决了不平衡的调用问题,但视觉差距(rootviewcontroller、差距、呈现的差距)变得(显然)更大。

当您调用通常的东西时,演示的缓慢也很明显:

// 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 上执行直接过渡,而无需父 View Controller 的可见轻弹。现在,同样的事情 – 父 View Controller 在过渡期间轻弹,即使它都在没有动画的情况下处理。

p>

有人将此视为问题吗?任何解决方案?我很乐意解决这个问题,而无需为我需要完美传输的每件事使用 UIWindow 做一些有趣的魔术。

最佳答案

我不确定要求仅限于拥有 Root View Controller 并在那里呈现任何内容。

但根据您的代码,它有欢迎 View Controller 的东西,我认为在这种情况下,这个逻辑更有用。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Conditions

    if (#first launch condition#) {
        // quite small controller containing Welcome showcase
        WelcomeViewController *w = ....

        //It can be navigation or tab bar controller which have "w" as rootviewcontroller
        [self.window setRootViewController:w];
    }

    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 = ....
        //It can be navigation or tab bar controller which have "item" as rootviewcontroller
        [self.window setRootViewController:item];
    }

    [self.window makeKeyAndVisible];

}

关于iOS 8 – 在设置关键窗口或关闭并立即呈现另一个 View Controller 后快速呈现 View Controller 时出现故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25977717/

相关文章:

iphone - IB - 无法为 View Controller 分配类

ios - 如何在按下 CollectionViewCell 内的按钮后呈现 ViewController

iOS:呈现 MFMailComposerViewController 时崩溃

ios - 制作一个按钮,其背景和内容仅在指定的内部矩形内绘制(而不是在其所有框架内)

ios - 照片查看器 iPad 和 iPhone

ios - Objective-C 函数通过在方法签名中指定关系来更新 Core Data 关系

ios - tableView 没有出现在 ViewController 中(swift)

ios - 使用自定义转换时, View Controller 是否会被完全删除?

iOS App 导航

iphone - 如何将 XCode 项目保存为模板以供其他应用使用?