NSView的addSubview方法本质上很慢吗? (可可 OSX)

发布于 2024-08-24 18:34:58 字数 230 浏览 7 评论 0原文

当我加载一个大型项目时,我试图加快我的 gui 加载速度,加载速度非常慢(gui 是组和子组的表示,由许多视图组成)。在此过程中,我查看了某些代码段的执行时间,发现对 addsubview 的调用大多数时间需要 10 到 20 毫秒。我正在查看的子视图是一个披露按钮。我想知道这种方法是否本质上很慢,或者是否还有其他因素在起作用?添加子视图所需的时间是否取决于子视图的复杂性,或者这不是一个因素?另外,是否有其他方法可以用来添加可能更快的子视图?

I am trying to speed my gui that loads very slow slow when I am loading a large project (the gui is a representation of groups and sub groups and is made up of many views). During this process I was looking at how long certain code segments take to execute and I have found that a call to addsubview is taking between 10 and 20 milliseconds most of the time. The subview I was looking at is a disclosure button. I am wondering if this method is just inherently slow or is their some other factor at work here? Is the time it takes to add the subview dependent on the complexity of the subview or is that not a factor? Also, is there some other method that can be used to add a subview that might be faster?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

2024-08-31 18:34:58

您可以尝试 -setSubviews: 它采用子视图数组。这可能比您自己多次调用 -addSubview: 更快。

否则, -addSubview: 和 -addSubview:positioned:relativeTo: 是插入子视图的唯一其他方法。

不过,我很好奇,为什么单个子视图要慢 10 - 20 毫秒?
您想添加多少个子视图?

可能存在使用 NSCell 的替代设计,该设计可能更快,但如果不知道有关您要完成的任务的更多细节,则很难知道。

You could try -setSubviews: which takes an array of subviews. This may be faster then calling -addSubview: multiple times yourself.

Otherwise, -addSubview: and -addSubview:positioned:relativeTo: are the only other methods for inserting subviews.

I'm curious, though, why is 10 - 20 ms to slow for a single subview?
How many subviews are you trying to add?

It is possible there is an alternative design using NSCell's that may be faster, but without know more details about what you are trying to accomplish, it is difficult to know.

绅刃 2024-08-31 18:34:58

重新排列视图层次结构通常不是您经常做的事情。您可以隐藏和取消隐藏子视图,而不是添加和删除子视图。

Rearranging the view hierarchy isn't something you'd typically do very often. Instead of adding and removing subviews, you could hide and unhide them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文