我使用以下代码将标签沿 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"];
但在这种情况下,在动画结束时标签会移回其原始位置。如何确保它停留在移动的位置。
有没有什么好的方法可以在不使用计时器和我们自己更改坐标的情况下做到这一点。
最佳答案
动画完成后,将其删除。这就是为什么它会弹回来。将其添加到您的动画中:
theAnimation.removedOnCompletion = NO;
theAnimation.fillMode = kCAFillModeForwards;
这将防止动画被删除,并告诉动画在完成后保持其最终状态。
关于iphone - 如何在 iPhone 中使用 CABasicAnimation 在 x 方向移动 View 或标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1555415/