Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need help with Animation Callbacks (iPhone)

I am creating an application in iPhone and I have several UIViews and layers in it. I am doing some animations using CAKeyframeAnimation class and since the animations have to be chained, I have overridden the animationDidStop method in UIView.

I am getting the callbacks properly, however I just couldn't figure out how I can find which animation was ended so that I can start the next one. Only parameters to the callback function is a CAAnimation object and a boolean.

I can workaround this problem by setting a property in the class and using an enum for the various animations I use. However I just wanted to know if there is any built in attributes in the callbacks which I can set in the CAKeyframeAnimation object and then refer the same in the callback.

Any help would be greatly appreciated!

like image 375
Jugs Avatar asked Jan 03 '09 11:01

Jugs


1 Answers

You can specify a name for an animation and read it in your delegate method.

[animation setValue:"firstAnimation" forKey:@"name"];

...

- (void)animationDidStop:(CAAnimation*)animation finished:(BOOL)finished {
  if([[animation valueForKey:@"name"] isEqual:@"firstAnimation"] && finished) {
    ...
  }
}
like image 125
Mel Avatar answered Sep 21 '22 19:09

Mel