Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CAAnimation with callback on step

I have a CAAnimation that uses a timing function. I need callbacks to happen consistently thought the animation. Similar to jQuery's step callback. I have scoured the internet for a solution to this but have not been able to find one. (maybe I am not searching correctly)

My code thus far:

CABasicAnimation *rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat:rotation / 180.0 * M_PI];
rotationAnimation.duration = duration;
rotationAnimation.repeatCount = 0;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];

[_image.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];

I know the delegate has these two methods:

 animationDidStart:
 animationDidStop:finished:

It would be nice if there was a way to create a category to implement an

- animationProgress:

Or something similar. Or maybe CAAnimations aren't the solution.

How can I achieve this with CAAnimations or any alternative?

like image 992
brenjt Avatar asked Nov 11 '22 15:11

brenjt


1 Answers

    CABasicAnimation *basicAnimation=[CABasicAnimation animationWithKeyPath:<AnimatableProperty>];
    CALayer *layerToAnimate=[CALayer layer];

    [CATransaction begin];
    [CATransaction setCompletionBlock:^{
       //Stuff to be done on completion
    }];
    [layerToAnimate addAnimation:basicAnimation forKey:@"myCustomAnimation"];
    [CATransaction commit];
like image 158
Mrug Avatar answered Jan 04 '23 02:01

Mrug