Type Property


Each keyframe value is used in turn, no interpolated values are calculated.


static let discrete: CAAnimationCalculationMode


Keyframe animations based on discrete calculation interpolation require one less element in the values array than the keyTimes array. Each value / keyTime pair represents the value from the specified time until the next keyframe.

For example, given the CAKeyframeAnimation created in Listing 1, the penultimate keyTime, 0.75, has a related value of 60. The value of position.y will remain at 60 until the animation completes.

Listing 1

Creating discrete keyframes

let keyframeAnimation = CAKeyframeAnimation(keyPath: "position.y")
keyframeAnimation.calculationMode = kCAAnimationDiscrete
// keyframe 0: (0, 310), keyframe 1: (0.25, 60), keyframe 2: (0.5, 120), keyframe 3: (0.75, 60)
keyframeAnimation.keyTimes = [0, 0.25, 0.5, 0.75, 1]
keyframeAnimation.values = [310, 60, 120, 60]

A layer animated with the keyframe animation created by the code above and with linearly interpolated horizontal movement would describe a path similar to Figure 1.

Figure 1

Tracing the path of an animation using discrete keyframes

Tracing the path of an animation using discrete keyframes

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software