且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

渐变动画 - 慢下来并加快速度

更新时间:2023-01-31 08:21:00

要使用关键帧动画,请尝试:

To use a keyframe animation, try:

let gradientAnimation = CAKeyframeAnimation(keyPath: "locations")
gradientAnimation.values = [[0.0, 0.0, 0.25], [0.375, 0.5, 0.625], [0.75, 1.0, 1.0]]
gradientAnimation.duration = 3.0
gradientAnimation.repeatCount = Float.infinity
gradientLayer.add(gradientAnimation, forKey: nil)

这将平均三次之间。要更改关键帧出现的时间,请设置 keyTimes

This will go between the three times equally. To change the times at which the keyframes occur, set keyTimes:

gradientAnimation.keyTimes = [0.0, 0.4, 1.0]

这将设置动画的百分比应为传递给中的每个元素以反映动画的当前状态。这也应该与具有相同的长度。

This will set the percentage of the animation should be passed for each element in values to reflect the current state of the animation. This should also have the same length as values.

我实际上并不知道Swift,所以这个应该工作,但我无法保证。

I don’t actually know Swift, so this should work, but I can’t guarantee it.