Pre*_*van 6 cocoa-touch objective-c cabasicanimation ipad ios
在我的应用程序中,我使用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;
}
Run Code Online (Sandbox Code Playgroud)
小智 6
我认为改变速度的最佳方法是改变你的图层的时间系统
displayLabel.layer.timeOffset =
[displayLabel.layer convertTime:CACurrentMediaTime() fromLayer:nil];
displayLabel.layer.beginTime = CACurrentMediaTime();
displayLabel.layer.speed= slider.value;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5041 次 |
| 最近记录: |