落ちているコインを作成しようとしています。コインイメージは、2つのCABasicAnimationsを持つCALayerです.1つは転倒、1つは回転です。落ちるアニメーションが終わると、そこにとどまります。ランダムアニメーションになるはずの回転アニメーションは毎回違う角度で終了しますが、元の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
fillModeのことがそれを解決しました。神はなぜそれが必要なのか知っています:) – Mikle
@Allan 'fillMode'が' kCAFillModeForwards'に設定される必要がある理由は何ですか? – pixelfreak