隐藏或删除 uiLabels 以提高性能

发布于 2024-10-28 00:58:13 字数 331 浏览 4 评论 0原文

我在长滚动视图上有 200 多个 uiLabels,我需要提高滚动性能。当标签不在视图中时,隐藏和取消隐藏标签更好,还是释放它们并重新创建它们更好? 我已经在它们上放置了标签,我目前正在使用这些标签来隐藏/取消隐藏:

for (int i=0; i<42; i++) {
        [theScroller viewWithTag:i].hidden = NO;
    }

反之亦然,由滚动 contentOffset.y 值触发。

我有我的 uiLabels 集合在 plist 中,所以它也很容易发布和重建它们?

感谢您的帮助..

I have 200+ uiLabels on a long scrollview, I need to improve scrolling performance. Is it better to hide and unhide labels, or release them and recreate them, when they are out of view?
I have put tags on them, I am currently using those to hide / unhide with:

for (int i=0; i<42; i++) {
        [theScroller viewWithTag:i].hidden = NO;
    }

and visa versa, triggered by scroll contentOffset.y values..

I have my uiLabels collection in a plist so its also easy to release and rebuild them?

thanks for any help..

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

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

发布评论

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

评论(4

胡渣熟男 2024-11-04 00:58:13

@Mark是的,最好释放标签,就好像它们不在视图中,不在使用中一样,这样它们会提高性能并帮助您进行内存管理。

@Mark yes it would be better to release the labels,as if they are out of view,not in use,so they will improve the performance and also help you for memory management.

皓月长歌 2024-11-04 00:58:13

拥有 200 多个视图会因以下原因降低性能:

  • 内存使用
  • 显示管理/动画

删除和释放隐藏标签并在需要时重新创建它们绝对是更好的选择:内存占用会更低,并且超级视图只有几个子视图需要管理(加上重新创建标签的开销并没有那么高)。

如果您的滚动视图+标签行为接近表视图的行为,则还有进一步改进的空间:标签重用。从其超级视图中删除隐藏标签,更改其标题/样式并将其重新添加到新位置。

Having 200+ views reduces performances due to:

  • Memory usage
  • Display management / animations

It would absolutely be better to remove and release hidden labels and recreate them when needed: memory footprint would be lower and the superview would have only a few subviews to manage (plus the overhead of recreating labels is not so high).

If your scrollview + labels behavior is close to what a table view does, there is room for further improvement: label reuse. Remove hidden labels from their superview, change their title / style and re-add them at their new position.

鹿港巷口少年归 2024-11-04 00:58:13

可能有助于提高性能的一件事是将标签设置为不透明。使用透明背景的视图时,性能会下降。

动态创建它们绝对是一个解决方案,但是,您可能会注意到滚动可能会时不时地挂起,或者标签在滚动后不久才出现。

另一种解决方案是使用本文中的方法< /a>.这个想法是,您将在视图上预渲染标签,并最终得到一个静态视图,当您滚动时,该视图应该可以很好地工作。

One thing that may help performance is to set your labels as opaque. The performance will decrease when using views with transparent backgrounds.

Creating them on the fly is definitely a solution, however, you may notice that the scrolling may hang every now and then or that the labels will not appear only after a short while after you've scrolled.

Another solution would be to use the approach from this article. The idea is that you would pre-render the labels on the view and end up with a single static view that should work pretty nicely when you're scrolling around.

风月客 2024-11-04 00:58:13

如果每个标签都是刚性的,您可以尝试使用 tableView 代替滚动视图。

使用自定义表格单元格,每个单元格都有您的标签。

You can try using a tableView insteand of scroll view if each label is rigid.

Use a custom table cell and each cell have your label.

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