开发者

Using drawRect, setNeedsDisplay and layoutSubViews

开发者 https://www.devze.com 2023-01-12 13:13 出处:网络
Is there any ground rule for using methods like drawRect, setNeedsDisplay and layou开发者_高级运维tSubViews?

Is there any ground rule for using methods like drawRect, setNeedsDisplay and layou开发者_高级运维tSubViews? I believe they adversely affect the app performance. Is there any preferred alternatives for these messages?


While this isn't an exact duplicate of this question, I believe my answer there still applies.

In summary, -drawRect: will redraw the content within a view, which is an expensive operation. Avoid redrawing if you can by layering content and moving or hiding those layers as needed.

However, these redraws typically will only have a significant performance impact if there are many of them done in rapid succession, like when trying to animate content. One-off redraws of static UI elements will not perceptively slow things down.

0

精彩评论

暂无评论...
验证码 换一张
取 消