Instead of letting drawRect
redraw thousands of point every time, I think there are several ways to "cache the image on screen" and any additional drawing, we will add to that image, and just show that image when it is time to drawRect
:
Use BitmapContext and draw to a bitmap, and in
drawRect
, draw this bitmap.Use
CGLayer
and draw theCGLayer
indrawRect
, and this may be faster than method 1, as this image is cached in the graphics card (and it will not count towards the RAM usage for the "memory warning" on iOS?)Draw to a
CGImage
, and use the view's layer:view.layer.contents = (id) cgimage;
So there seems to be three methods, and I think CALayer
in method (3) can only use a CGImage
to achieve it. CALayer
by itself cannot cache a screen image, not like CGLayer
in (2).
Is method (2) the fastest out of all three, and are there other methods that can accomplish this? I actually plan to animate a few screen images, (looping over 5 or 6 of them), and will try using CADisplayLink
to try a highest frame rate of 60fps. Will any of method (1), (2), or (3) use the memory in graphics card and therefore not use the RAM and therefore less likely to get a memory warning from iOS too?