Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CABasicAnimation delegate for animationDidStop?

I am following the example at the bottom of the page to call an animationDidStop function.

http://www.informit.com/articles/article.aspx?p=1168314&seqNum=2

The author says:

I have an object that is designed specifically to be the delegate of animations and all it does is hold a reference to the target object, accept the animationDidStop: message and then release itself.

This suggests you shouldn't do:

[animation setDelegate:self];

I'm pretty new to app programming can someone outline how I might do this? Or send me a link where it is explained.

like image 954
user157733 Avatar asked Apr 08 '10 11:04

user157733


2 Answers

Implement:

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag

on your delegate object. You can also implement:

- (void)animationDidStart:(CAAnimation *)theAnimation

to receive a call when the animation starts.

For more info, see the Delegates section of: http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Reference/CAAnimation_class/Introduction/Introduction.html

like image 128
thefaj Avatar answered Nov 06 '22 06:11

thefaj


Sometimes setting your layer's actual value to the toValue when the animation completes is required. When it's a more complex animation such as animating the colors of a CAGradientLayer, this is required.

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
  self.gradientLayer.colors = (NSArray *)((CABasicAnimation*)theAnimation).toValue;
}
like image 4
james_womack Avatar answered Nov 06 '22 06:11

james_womack