ios - presentViewController 性能低下 - 取决于 presentING Controller 的复杂性?

标签 ios iphone performance cocoa-touch instruments

我正在展示一个 View Controller :

SCAAboutController2 *controller = [[SCAAboutController2 alloc] initWithNibName:nil bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
[self presentViewController:navController animated:YES completion:nil];

设备在呈现之前挂起 3-4 秒。我曾尝试使用 Instruments 对此进行诊断,但似乎大部分时间都花在 main -

enter image description here

这是相同的配置文件,但未隐藏系统库:

enter image description here

我无法识别这些消息,所以我不确定如何开始调试我的性能问题。

我在别处读到我应该检查主代码是否在主线程上执行。但是,以下更改并没有改善任何东西:

dispatch_async(dispatch_get_main_queue(), ^{
        SCAAboutController2 *controller = [[SCAAboutController2 alloc] initWithNibName:nil bundle:nil];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
        [self presentViewController:navController animated:YES completion:nil];
    });

我很快就没有了关于如何进步的想法。我该如何进一步调查,和/或呈现缓慢的根本原因可能是什么?

编辑

一些令人困惑的发现:

  • 我已经从呈现的 View Controller 中删除了所有代码。性能不受影响。
  • 我有另一个 Controller ,我通过不同的按钮从同一个地方展示它。它同样慢。
  • presentinging Controller 有很多 subview 和约束——甚至是一些 subview Controller 。删除填充这些代码的代码可以解决问题。
  • 在呈现 Controller 的 viewWillDisappear 中没有添加任何内容。

编辑2

我发现问题主要围绕我在主(呈现) Controller 中添加的一系列布局约束。具体来说,我循环遍历一些子 Controller (teamController 类型)并添加约束:

[self.browser addConstraint:[NSLayoutConstraint constraintWithItem:teamController.view
                                                         attribute:NSLayoutAttributeWidth
                                                         relatedBy:NSLayoutRelationEqual
                                                            toItem:self.browser
                                                         attribute:NSLayoutAttributeWidth
                                                        multiplier:1
                                                          constant:0]];

只有 10 个子 Controller 。也很奇怪:如果我改用以下内容,我就没有这样的问题:

[self.browser.contentView addConstraint:[NSLayoutConstraint constraintWithItem:teamController.view
                                                                     attribute:NSLayoutAttributeWidth
                                                                     relatedBy:NSLayoutRelationEqual
                                                                        toItem:nil
                                                                     attribute:NSLayoutAttributeNotAnAttribute
                                                                    multiplier:1
                                                                      constant:200]];

我仍然很困惑为什么这些约束会导致另一个模态的呈现挂起,以及为什么约束的一个变体与另一个变体的行为截然不同。

最佳答案

不确定这是原作者的问题,但这里有一些东西为我解决了类似的问题:我试图从 didSelectRowAtIndexPath 中呈现一个 View ,我不得不调用 deselectRowAtIndexPath之前。如果这可以帮助某人...

关于ios - presentViewController 性能低下 - 取决于 presentING Controller 的复杂性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22585416/

相关文章:

ios - 内存泄漏。我怎样才能修复它们

c++ - 具有许多自定义项的 QListWidget 性能

iphone - 检测动画 View 上的触摸

iPhone + 配置文件 + app-info.plist + entitlements.plist = iPhoneApp ?如何 ? entitlemets.plist 到底有什么作用?

performance - 有效计数目录和子文件夹中具有特定名称的文件

java - 通过设置 BasicDataSource 属性 testOnBorrow=false 来提高 web app/rest-api 性能,有风险吗?

ios - wait_fences : failed to receive reply: 10004003 (only on iPad)

php - AFNetworking 1.x 将 JSON 发布到 PHP

ios - 如何获得从 awakeFromNib 到 mainViewController.m 的对象高度?

ios - 将 JSON 数据的 NSString 转换为 NSArray