animationviewredrawcatiledlayer

CATiledLayer with animating content


I've got this UIView which is backed by a CATiledLayer. My setup works pretty smooth at the moment but the horror starts when I want to animate certain view objects on this CATiledLayer.

I've read that I can force the CATiledLayer to redraw itself by using setNeedsDisplay. But this actually redraws everything on the screen. So all the tiles are loaded all over again.

How should I update my layer when something is animating? Let's take the following as an example: I've got 6 green rectangles on my layer and when I press a UIButton I'd like to change the color of rectangle number 4 to red and reposition rectangle 1 2 and 3 on a bezier curve.


Solution

  • you can use CATiledView:setNeedsDisplayInRect: to radraw only portions of the layer.

    in your case you should:

    1. redraw 4 with new color
    2. redraw old positions of 1, 2 and 3 with no rectangles
    3. redraw new positions on 1, 2 and 3