我正在开发一个应用程序,在其中我使用了相当多的动画。我发现为了优化spritesheet
,我们可以预加载动画,而且效果非常好。这是链接。
但我在问,这种优化是否也可以像这样使用CABasicAnimations
:
CABasicAnimation * myAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
myAnimation.fromValue = [NSNumber numberWithFloat:0.0f]
myAnimation.toValue = [NSNumber numberWithFloat:200.0f];
myAnimation.duration = t;
myAnimation.repeatCount = 1;
[myUIImageView.layer addAnimation:myAnimation forKey:@"myAnimation"];
因为它与UIImageView
一起工作,即使它是基于CABasicAnimation
的。
那么,有可能用这种过程预加载我的CABasicAnimation
吗?如果没有,怎么办?
谢谢!
使用CAKeyframeAnimation
。将其calculationMode
设置为kCAAnimationDiscrete
。将其values
设置为NSNumber
对象的NSArray
,每个动画帧在精灵表中的x偏移对应一个对象。