带步骤回调的CAAnimation

bre*_*njt 5 animation objective-c callback caanimation

我有一个CAAnimation使用计时功能.我需要回调一直想到动画.类似于jQuery的步骤回调.我已经在互联网上寻找解决方案,但一直找不到.(也许我没有正确搜索)

我的代码到目前为止:

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"];
Run Code Online (Sandbox Code Playgroud)

我知道委托有这两种方法:

– animationDidStart:
– animationDidStop:finished:
Run Code Online (Sandbox Code Playgroud)

如果有一种方法来创建一个类别来实现一个,那将是很好的

- animationProgress:
Run Code Online (Sandbox Code Playgroud)

或类似的东西.或者可能CAAnimations不是解决方案.

如何使用CAAnimations或替代方案实现此目的?

eva*_*ent 0

您可能想使用

UIView 的 animateWithDuration:delay:options:animations:completion:

一个简单的设置方法是

- (void)animateStuff {
 [UIView animateWithDuration:duration
                       delay:delay
                     options:UIViewAnimationOptionTransitionNone
                  animations:^{ // custom animations }
                  completion:^(BOOL finished) {
                       // check if you want to continue with
                       if (<check to continue>) {
                           [self animateStuff];
                       }
                  }];
}
Run Code Online (Sandbox Code Playgroud)

如果您可以将整个动画分解为小片段,这会非常有用。使用上面的代码,您可以为每个较小的片段设置动画,并继续这样做,直到整个动画完成。