在我的应用程序中,我使用 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;
}