我正在移植一个现有的 iOS 应用程序来学习 C4,我需要使用自定义动画来使用 CAKeyframeAnimation 从屏幕外滑入具有“弹入”效果的图像。
对我来说,使用 C4 实现更复杂的动画的最佳方法是什么?
图像创建
C4Image *v = [C4Image imageNamed:@"assets/images/ca/defense.png"];
v.frame = CGRectMake(1500, 300, 400, 400); // off screen
[self addImage:v];
先前实现中使用的 CAKeyframeAnimation
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position.x"];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
animation.duration = 0.5;
int steps = 100;
NSMutableArray *values = [NSMutableArray arrayWithCapacity:steps];
double value = 0;
float e = 2.71;
for (int t = 0; t < steps; t++) {
value = 200 * pow(e, -0.055*t) * cos(0.08*t) + x; //418
[values addObject:[NSNumber numberWithFloat:value]];
}
animation.values = values;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.delegate = self;
animation.beginTime = CACurrentMediaTime() + delay;