2

I was pretty sure I had seen discussions of this around the Net, but now I can't seem to find anything. The question is simple: is there a way to use for example CABasicAnimation to animate a property on an object that's not a ´CALayer´? (Say, the ´volume´ property on an ´AVAudioPlayer´.)

If not, is there a way to make it work other than subclassing ´CALayer´? Maybe some protocol to conform to?

EDIT: How about doing this on the iPhone OS?

Felixyz
  • 19,053
  • 14
  • 65
  • 60

1 Answers1

7

You can indeed do this. Your object must implement the NSAnimatablePropertyContainer protocol and return a valid CAAnimation object for each property you want to animate in the +defaultAnimationForKey: class method.

To answer your updated question, no, you can't do this on the iPhone at present as there is no NSAnimatablePropertyContainer protocol available in iPhone OS and you can't get an animator proxy object from other objects.

Rob Keniger
  • 45,830
  • 6
  • 101
  • 134
  • Thanks Rob! Now the follow-up question: is this possible on the iPhone OS? – Felixyz Mar 01 '10 at 02:01
  • Any pointers as to how one would one go about implementing NSAnimatablePropertyContainer? Specifically the - (id)animator; method? – dmaclach Jul 14 '11 at 17:19
  • 1
    Similar answer by the same author with more detail: http://stackoverflow.com/a/10168831/377384 (thanks Rob!) – lindon fox Jan 31 '15 at 02:58