<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "QuartzCore",
  "identifier" : "/documentation/QuartzCore/CAKeyframeAnimation",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Animation"
    ],
    "preciseIdentifier" : "c:objc(cs)CAKeyframeAnimation"
  },
  "title" : "CAKeyframeAnimation"
}
-->

# CAKeyframeAnimation

An object that provides keyframe animation capabilities for a layer object.

```
class CAKeyframeAnimation
```

## Overview

You create a [`CAKeyframeAnimation`](/documentation/QuartzCore/CAKeyframeAnimation) object using the inherited [`init(keyPath:)`](/documentation/QuartzCore/CAPropertyAnimation/init(keyPath:)) method, specifying the key path of the property that you want to animate on the layer. You can then specify the keyframe values to use to control the timing and animation behavior.

For most types of animations, you specify the keyframe values using the [`values`](/documentation/QuartzCore/CAKeyframeAnimation/values) and [`keyTimes`](/documentation/QuartzCore/CAKeyframeAnimation/keyTimes) properties. During the animation, Core Animation generates intermediate values by interpolating between the values you provide. When animating a value that is a coordinate point, such as the layer’s position, you can specify a [`path`](/documentation/QuartzCore/CAKeyframeAnimation/path) for that point to follow instead of individual values. The pacing of the animation is controlled by the timing information you provide.

The following code shows how to create a keyframe animation that animates a layer’s background color from red to green to blue over a two second duration.

```swift
let colorKeyframeAnimation = CAKeyframeAnimation(keyPath: "backgroundColor")

colorKeyframeAnimation.values = [UIColor.red.cgColor,
                                 UIColor.green.cgColor,
                                 UIColor.blue.cgColor]
colorKeyframeAnimation.keyTimes = [0, 0.5, 1]
colorKeyframeAnimation.duration = 2
```

## Topics

### Providing keyframe values

[`values`](/documentation/QuartzCore/CAKeyframeAnimation/values)

An array of objects that specify the keyframe values to use for the animation.

[`path`](/documentation/QuartzCore/CAKeyframeAnimation/path)

The path for a point-based property to follow.

### Keyframe timing

[`keyTimes`](/documentation/QuartzCore/CAKeyframeAnimation/keyTimes)

An optional array of `NSNumber` objects that define the time at which to apply a given keyframe segment.

[`timingFunctions`](/documentation/QuartzCore/CAKeyframeAnimation/timingFunctions)

An optional array of `CAMediaTimingFunction` objects that define the pacing for each keyframe segment.

[`calculationMode`](/documentation/QuartzCore/CAKeyframeAnimation/calculationMode)

Specifies how intermediate keyframe values are calculated by the receiver.

### Rotation Mode Attribute

[`rotationMode`](/documentation/QuartzCore/CAKeyframeAnimation/rotationMode)

Determines whether objects animating along the path rotate to match the path tangent.

### Cubic Mode Attributes

[`tensionValues`](/documentation/QuartzCore/CAKeyframeAnimation/tensionValues)

An array of numbers that define the tightness of the curve.

[`continuityValues`](/documentation/QuartzCore/CAKeyframeAnimation/continuityValues)

An array of numbers that define the sharpness of the timing curve’s corners.

[`biasValues`](/documentation/QuartzCore/CAKeyframeAnimation/biasValues)

An array of numbers that define the position of the curve relative to a control point.

### Constants

[Rotation Mode Values](/documentation/QuartzCore/rotation-mode-values)

These constants are used by the [`rotationMode`](/documentation/QuartzCore/CAKeyframeAnimation/rotationMode) property.

[Value calculation modes](/documentation/QuartzCore/value-calculation-modes)

These constants are used by the [`calculationMode`](/documentation/QuartzCore/CAKeyframeAnimation/calculationMode) property.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)