presentViewController性能下降 - 取决于presentING控制器的复杂性? [英] Slow performance for presentViewController - depends on complexity of presentING controller?

查看:110
本文介绍了presentViewController性能下降 - 取决于presentING控制器的复杂性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在展示一个视图控制器:

I am presenting a 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 -

The device hangs for 3-4 seconds before presenting. I have attempted to diagnose this using Instruments, but it seems most of the time is spent in main -

< img src =https://i.stack.imgur.com/HxoPk.pngalt =在此处输入图像说明>

这是相同的个人资料,但系统库取消隐藏:

Here is the same profile but with System Libraries unhidden:

这些消息都不是我能识别的,所以我不知道如何开始调试我的性能问题。

None of these messages are recognizable to me, so I'm not sure how to start debugging my performance issue.

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

I read elsewhere that I should check that the main code is executing on the main thread. However, the following change is not improving anything:

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];
    });

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

I've quickly run out of ideas on how to progress. How might I investigate further, and/or what might be the root cause of the slow presentation?

编辑

一些令人困惑的发现:


  • 我已从显示的视图控制器中删除了所有代码。性能不受影响。

  • 我有另一个控制器,我通过不同的按钮从同一个地方出示。它同样很慢。

  • 呈现 ing 控制器有很多子视图和约束 - 甚至是一些子视图控制器。删除填充这些代码的代码可以解决问题。

  • 在呈现控制器的 viewWillDisappear 中没有添加任何内容。

  • I've removed all code from the presented view controller. The performance is unaffected.
  • I have another controller which I present from the same place via a different button. It is equally slow.
  • the presentinging controller has quite a lot of subviews and constraints - even some child view controllers. Removing the code that populates these resolves the issue.
  • nothing is added in the viewWillDisappear of the presenting controller.

编辑2

我发现问题集中在我在主(呈现)控制器中添加的一系列布局约束。具体来说,我遍历一些子控制器(类型 teamController )并添加约束:

I have discovered that the issues centers around a series of layout constraints I add in the main (presenting) controller. Specifically, I loop through some child controllers (of type teamController) and add the constraint:

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

只有10个子控制器。同样奇怪:如果我使用以下代码,我就没有这样的问题了:

There are only 10 child controllers. Also strange: I have no such issues if I use the following instead:

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

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

I am still very confused as to why these constraints would cause the presentation of another modal to hang, and why one variation of the constraint behaves drastically differently to the other.

推荐答案

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

Not sure this was the original author's problem but here is something that solved a similar problem for me: I was trying to present a view from didSelectRowAtIndexPath and I had to call deselectRowAtIndexPath before. If this may help someone...

这篇关于presentViewController性能下降 - 取决于presentING控制器的复杂性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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