我正在尝试创建一个落下的硬币。硬币图像是一个带有 2 个 CABasicAnimations 的 CALayer - 一个跌落和一个旋转。当跌落动画结束时,它会停留在那里。不过,旋转动画应该是随机的,并且每次都以不同的角度结束,但它只是弹回原始的 CALAyer 图像。
我希望它保持在完成动画的角度。是否可以?我该怎么做?
代码:
//Moving down animation:
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
anim.duration = 1;
anim.autoreverses = NO;
anim.removedOnCompletion = YES;
anim.fromValue = [NSNumber numberWithInt: -80 - row_height * (8 - _col)];
anim.toValue = [NSNumber numberWithInt: 0];
//Rotation Animation:
CABasicAnimation *rota = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rota.duration = 4;
rota.autoreverses = NO;
rota.removedOnCompletion = NO;
rota.fromValue = [NSNumber numberWithFloat: 0];
rota.toValue = [NSNumber numberWithFloat: 2.5 * 3.15 ];
[cl addAnimation: rota forKey: @"rotation"];
[cl addAnimation: anim forKey: @"animateFalling"];