在我的應用程序中,我將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