我使用以下代码在x方向上将标签从一个位置移动到另一个位置
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
theAnimation.duration=1;
theAnimation.repeatCount=1;
theAnimation.autoreverses=NO;
theAnimation.fromValue=[NSNumber numberWithFloat:0];
theAnimation.toValue=[NSNumber numberWithFloat:80];
[lbl.layer addAnimation:theAnimation forKey:@"animateLayer"];
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,在动画结束时,标签会移回原来的位置.如何确保它停留在移动位置.
有没有什么好方法可以不使用计时器和我们自己更改坐标.
Ale*_*lex 14
动画完成后,它将被删除.这就是为什么它会重新开始.将其添加到动画中:
theAnimation.removedOnCompletion = NO;
theAnimation.fillMode = kCAFillModeForwards;
Run Code Online (Sandbox Code Playgroud)
这将阻止动画被删除,并告诉动画在完成时保持其最终状态.
| 归档时间: |
|
| 查看次数: |
7313 次 |
| 最近记录: |