drawRect: speed and CGContextDrawRadialGradient (super slow?)

北城以北 提交于 2019-12-10 21:14:32

问题


I'm having problems with my UIView subclass' drawRect: function. I use CGContextDrawRadialGradient() in it, and it. When the user drags my UIView it struggled to keep up if I include the gradient.

Using Time Profiler I see that literally > 98% of my time is spent in my subclass' drawRect: method.

First: would using a static image of a gradient be faster? Second: is there any way to speed this up? Can I cache the gradient somehow? it doesn't change much but paths around it and intersecting it do change as you drag the UIView.

If anybody knows of a general guide on how to make drawRect: methods not suck up all the cpu cycles, that would be awesome.


回答1:


I'm having the same problem. One solution is to draw a smaller gradient and scale it up. The results is not pixel perfect, but faster.

See also the ideas mentioned in this answer.



来源:https://stackoverflow.com/questions/4425635/drawrect-speed-and-cgcontextdrawradialgradient-super-slow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!