Gradient Animation - Slow down and speed up

后端 未结 1 699
孤独总比滥情好
孤独总比滥情好 2021-01-15 23:16

I\'m animating a CAGradientLayer, similar to how Apple did with their \"Slide to Unlock\" animation on the home screen of iPhone. However my animation is a litt

相关标签:
1条回答
  • 2021-01-16 00:04

    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)
    

    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.

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

    0 讨论(0)
提交回复
热议问题