Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate a CALayer's bounds w/redraws

I am wondering how one might animate a CALayer's bounds so, on each bounds change, the layer calls drawInContext:. I've tried the 2 following methods on my CALayer subclass:

  • Setting needsDisplayOnBoundsChange to YES
  • Returning YES for the + (BOOL)needsDisplayForKey:(NSString*)key for the bounds key

Neither work. CALayer seems determined to use the layer's original contents and simply scale them according to contentsGravity (which, I assume, is for performance.) Is their a workaround for this or am I missing something obvious?

EDIT: And, incidentally, I noticed that my custom CALayer subclass is not calling initWithLayer: to create a presentationLayer - weird.

Thanks in advance, Sam

like image 876
Sam Avatar asked Sep 27 '11 23:09

Sam


1 Answers

You can use the technique outlined here: override CALayer's +needsDisplayForKey: method and it will redraw its content at every step of the animation.

like image 78
titaniumdecoy Avatar answered Oct 05 '22 03:10

titaniumdecoy