Mik*_*kle 39 iphone calayer cabasicanimation
我想创造一枚落硬币.硬币图像是一个带有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"];
Run Code Online (Sandbox Code Playgroud)
All*_*net 79
您是否将旋转动画的removedOnCompletion属性设置为NO,例如,
rota.removedOnCompletion = NO;
Run Code Online (Sandbox Code Playgroud)
这应该使表示层离开动画结束时的位置.默认值为YES,它将快照回模型值,即您描述的行为.
还应设置fillMode,即
rota.fillMode = kCAFillModeForwards;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25900 次 |
| 最近记录: |