我想创建一个正在下降的硬币。硬币图像是CALayer上的2个CABasicAnimations - 一个掉下来和一个旋转。当倒下的动画结束时,它停留在那里。虽然旋转动画应该是随机的,并且每次都以不同的角度结束,但它仍会弹出原始CALAyer图像。使用CABasicAnimation旋转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"];
我做到了。我添加了我用于问题的代码。 – Mikle 2009-09-04 12:08:50
fillMode的东西解决了它。天知道为什么需要:) – Mikle 2009-09-04 19:28:13
@Allan任何想法为什么'fillMode'需要设置为'kCAFillModeForwards'? – pixelfreak 2011-07-26 02:44:20