Trong ứng dụng của tôi, tôi đang sử dụng CABasicAnimation cho hoạt ảnh. Tôi muốn thay đổi tốc độ của hoạt ảnh động vì vậy tôi đã thêm một thanh trượt để thay đổi tốc độ. Sau đây là mã hoạt hình của tôi. Nhưng tôi không thể thay đổi tốc độ, khi tôi thay đổi giá trị của tốc độ không có gì xảy ra.Làm thế nào để thay đổi tốc độ trong khi hoạt hình 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;
}
Bản sao có thể có của [Thời lượng thay đổi (tốc độ) trên hoạt ảnh đang chạy] (https://stackoverflow.com/questions/21589483/change-duration-speed-on-a-running-animation) – Fattie
** Giải pháp đầy đủ cho năm 2017 ** ...https://stackoverflow.com/a/45787919/294884, phew – Fattie