CALayer
seems to have almost everything required to add properties to a layer at runtime, without subclassing, using a delegate and/or the layer's actions
property. However, one thing I have not figured out is how to trigger display updates when one of these dynamic properties changes in an animation.
I know how do this in a custom subclass of CALayer
: simply define the properties in the subclass, mark them @dynamic
, and override needsDisplayForKey:
and return YES
for the custom properties. Then display
will be invoked during animations, which, by default, will even trigger a call to the layer delegate's drawLayer:inContent:
method, if present (though it's of questionable usefulness, given that you've already got this subclass where you can implement drawInContext:
). However, I am trying to see if this is possible without subclassing CALayer.
I can get as far as supporting updates outside of animations using only a layer delegate, by installing a CAAction
in the layer's actions
property, or implementing actionForLayer:forKey:
in the layer delegate, and having that action send a setNeedsDisplay
message to the layer. However, actionForKey:
is apparently not called during an animation (makes sense, since it is used to trigger implicit animations), and there is no equivalent to needsDisplayForKey:
in the layer delegate protocol, that I can see.
So, is there any way to tell CALayer
to call display
for custom properties besides the above? Or is it not possible to implement animatable custom layer properties in a layer delegate alone? It seems like Apple would prefer one to use delegation when possible, but without a way to refresh the layer contents during an animation, the delegate interface is incomplete. Any suggestions?