我有CAAnimation
使用计时功能。我需要回调一直想到动画。与jQuery's step回调类似。我已经在互联网上寻找解决方案,但一直找不到。 (也许我没有正确搜索)
到目前为止我的代码:
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"];
我知道委托有这两种方法:
– animationDidStart:
– animationDidStop:finished:
如果有办法创建一个类别来实现
,那就太好了- animationProgress:
或类似的东西。或者CAAnimations
可能不是解决方案。
如何使用CAAnimations
或任何替代方案实现此目标?
答案 0 :(得分: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];
}
}];
}
如果您可以将整个动画分解成小片段,这很有用。使用上面的代码,您可以为每个较小的片段设置动画并继续这样做,直到整个动画完成。
答案 1 :(得分:0)
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];