gpt4 book ai didi

iphone - UITableView滚动性能悖论: Make subviews or use -drawRect:?

转载 作者:行者123 更新时间:2023-12-03 19:11:05 26 4
gpt4 key购买 nike

我正在阅读thourg this example (link) ...

从描述来看,这对我来说似乎是悖论:

When implementing a table view cell, there's a tension between optimal scrolling performance and optimal edit/reordering performance. You should typically use subviews in the cell's content view.

When you have an edit or reordering control, using subviews makes the implementation easier, and the animations perform better because UIKit doesn't have to redraw during animations.

结论: subview 速度更快,因为 UIKit 在动画期间不得重绘。所以滚动的时候一定不能一直调用-drawRect:。对吗?

然后,悖论:

If the content is complex, however (more than about three subviews), scrolling performance may suffer. If this becomes a problem, you can instead draw directly in a subview of the table view cell's content view.

结论:更喜欢 -drawRect:直接在表格 View 单元格上绘制。复杂单元格的更好滚动性能。比很多 subview 更好。

那么,好吧。什么是真的? subview 或 -drawRect:哪个更好?

就我而言,每个单元格大约有 12 个 subview 。他们实际上只是想说这个吗? “如果您最多只有 3 个 subview ,请使用它们。但如果您有更多 subview ,请使用 -drawRect: 并直接在单元格上绘制。”。但然后:为什么不总是更喜欢 -drawRect: 那么呢?

最佳答案

您可以将其总结为仅显示与功能。如果您的单元格的任务只是显示不会发生太大变化并保持静态的数据,请绘制它。如果您的单元格的任务是发挥功能,可以更改位置或由用户操纵(或者您有自定义动画),请考虑使用 subview 。

对此并没有真正硬性规定。您的用例可以很好地衡量哪种方法最好。有了 12 个 subview ,我会立即倾向于自定义绘图以获得速度优势。

Why not always prefer -drawRect: then?

通过使用 subview ,您可以免费获得很多东西。动画“更容易”。例如,使用 UIImageView 显示图像可以免费突出显示。这实际上取决于您的细胞的任务。

关于iphone - UITableView滚动性能悖论: Make subviews or use -drawRect:?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2607670/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com