性能问题:UIView coregraphics 在 Customcell 内绘制
我正在使用自定义单元格实现 UItableView。 我的自定义单元格内部有一个 UIView。
我试图在 UIView 中使用渐变绘制广泛的 CoreGraphics 形状,但我遇到了滚动性能问题 - 因为每次显示单元格时都会绘制自定义单元格的 UIView。
有没有办法可以以不同的方式做到这一点(例如,某种惰性绘图、异步绘图、UIView 缓存、防止单元格重绘等)以提高性能?
深深感谢任何帮助、意见和见解。
I am implementing a UItableView with custom cells.
My custom cell has a UIView inside of it.
I am trying to draw extensive CoreGraphics shapes with gradients in the UIView and I am running into scrolling performance problems -- since the customcell's UIView is getting drawn upon everytime the cell gets displayed.
Are there ways where I could do this differently (such as say, some kind of lazy drawing, drawing asynchronously, UIView caching, preventing the cell from redrawing etc) so as to improve performance?
Deeply appreciate any help, inputs, insights.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个想法不是每次在绘制时都计算图形,而是在 UIImageView 中将其渲染到屏幕外。然后你的细胞只需要块传输图像,这是尽可能快的。
您仍然可以延迟且异步地计算图像。您的代码结构可能类似于 Apple 示例代码 LazyTableImages。谷歌一下。在该示例代码中,慢的不是绘制时间,而是网络加载时间,但差异并不显着。
The idea is not to compute your graphics every time at draw time, but to render it offscreen in a UIImageView. Then your cell only has to blit the image, which is as fast as can be.
You can still compute your images lazily and asynchronously. The structure of your code could be similar to the Apple sample code LazyTableImages. Google for it. In that sample code, what's slow is not the drawing time, but the network loading time, but that difference is not significant.