我想創建一個正在下降的硬幣。硬幣圖像是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