drawRect:速度和CGContextDrawRadialGradient(超级慢?) [英] drawRect: speed and CGContextDrawRadialGradient (super slow?)
问题描述
我的 UIView
子类 drawRect:
函数遇到问题。
我在其中使用 CGContextDrawRadialGradient()
。
当用户拖动我的UIView时,如果我添加渐变,它就难以跟上。在子类的 drawRect
:方法中花费。
首先:使用静态的渐变图像会更快吗?
第二:有什么方法可以加快速度吗?我可以某种方式缓存渐变吗?它并没有太大变化,但是当拖动 UIView
时,围绕它的路径和与之相交的路径确实会发生变化。
如果任何人都知道如何制作 drawRect:
方法的一般指南,并不吸收所有的CPU周期,那真是太棒了。
我遇到了同样的问题。一种解决方案是绘制较小的渐变并将其放大。结果不是完美的像素,而是更快。
另请参见此答案。
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.
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.
这篇关于drawRect:速度和CGContextDrawRadialGradient(超级慢?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!