平稳加速运行中的旋转动画 [英] Smoothly speed up an running rotation animation
本文介绍了平稳加速运行中的旋转动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码旋转任何视图:
I use this code to rotate any view:
func rotateAnimation(theView: UIView, duration: CFTimeInterval = 20.0, repeatCount: Float = 200, toValue: CGFloat = CGFloat(.pi * 2.0)) {
let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
rotateAnimation.fromValue = 0.0
rotateAnimation.toValue = toValue
rotateAnimation.duration = duration
rotateAnimation.repeatCount = repeatCount
theView.layer.add(rotateAnimation, forKey: nil)
}
我想知道如何加快当前正在运行的动画的速度。例如,如果某个UIView随上面的代码一起旋转,那么如何通过一个不错的转换使该速度快两倍?
I would like to know how to speed up that currently running animation. If for example an UIView is rotating with the code above, how can I make that speed go twice as fast with a nice transation?
所以:调用rotationAnimation :以正常速度旋转-> 调用功能? -> UIView将平滑地旋转到所需速度更快-> UIView将继续以所需速度旋转。
So: calls rotateAnimation: rotating at normal speed -> calls ?function? -> UIView will smoothly go spinning faster to desired speed -> UIView will keep spinning at desired speed.
谢谢您的帮助。
推荐答案
请尝试下面的代码
let timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { (timer) in
self.viewToMove.layer.timeOffset = self.viewToMove.layer.convertTime(CACurrentMediaTime(), from: nil)
self.viewToMove.layer.beginTime = CACurrentMediaTime()
self.viewToMove.layer.speed += 0.5
}
timer.fire()
它将非常平滑地提高动画速度
It will Increase Animation speed very smoothly
这篇关于平稳加速运行中的旋转动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文