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
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.