在我的应用程序中,我将CABasicAnimation用于动画。我想动态改变动画的速度,所以我添加了一个滑块来改变速度。以下是我的动画代码。但我无法改变速度,当我改变速度值时什么也没有发生。如何在动画中更改速度CABasicAnimation
CABasicAnimation * a = [CABasicAnimation animationWithKeyPath:@"position"];
[a setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
CGPoint startPt = CGPointMake(self.view.bounds.size.width + displayLabel.bounds.size.width/2,
displayLabel.frame.origin.y);
CGPoint endPt = CGPointMake(displayLabel.bounds.size.width/-2, displayLabel.frame.origin.y);
[a setFromValue:[NSValue valueWithCGPoint:startPt]];
[a setToValue:[NSValue valueWithCGPoint:endPt]];
[a setAutoreverses:NO];
[a setDuration:speeds];
[a setRepeatCount:HUGE_VAL];
[displayLabel.layer addAnimation:a forKey:@"rotationAnimation"];
- (IBAction)speedSlider:(id)sender {
speeds = slider.value;
}
[更改正在运行的动画的持续时间(速度)]的可能重复(https://stackoverflow.com/questions/21589483/change-duration-speed-on-a-running-animation) – Fattie
**完整解决方案2017年** ...https://stackoverflow.com/a/45787919/294884,唷 – Fattie