<!--
{
  "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/CABasicAnimation",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Animation"
    ],
    "preciseIdentifier" : "c:objc(cs)CABasicAnimation"
  },
  "title" : "CABasicAnimation"
}
-->

# CABasicAnimation

An object that provides basic, single-keyframe animation capabilities for a layer property.

```
class CABasicAnimation
```

## Overview

You create an instance of  [`CABasicAnimation`](/documentation/QuartzCore/CABasicAnimation) using the inherited [`init(keyPath:)`](/documentation/QuartzCore/CAPropertyAnimation/init(keyPath:)) method, specifying the key path of the property to be animated in the render tree.

For example, you can animate a layer’s scalar (i.e. containing a single value) properties such as its [`opacity`](/documentation/QuartzCore/CALayer/opacity). The following code fades in a layer by animating its opacity from `0` to `1`.

```swift
let animation = CABasicAnimation(keyPath: "opacity") 
animation.fromValue = 0 
animation.toValue = 1
```

Non-scalar properties, such as [`backgroundColor`](/documentation/QuartzCore/CALayer/backgroundColor), can also be animated. Core Animation will interpolate between the [`fromValue`](/documentation/QuartzCore/CABasicAnimation/fromValue) color and the [`toValue`](/documentation/QuartzCore/CABasicAnimation/toValue) color. The animation created in the following code fades a layer’s background color from red to blue.

```swift
let animation = CABasicAnimation(keyPath: "backgroundColor")
animation.fromValue = NSColor.red.cgColor
animation.toValue = NSColor.blue.cgColor
```

If you want to animate the individual components of a non-scalar property with different values, you pass the values to [`toValue`](/documentation/QuartzCore/CABasicAnimation/toValue) and [`fromValue`](/documentation/QuartzCore/CABasicAnimation/fromValue) as arrays. The following animation moves a layer from `(0, 0)` to `(100, 100)`.

```swift
let animation = CABasicAnimation(keyPath: "position")
animation.fromValue = [0, 0]
animation.toValue = [100, 100]
```

The `keyPath` can access the individual components of a property. For example, the following animation stretches a layer by animating its [`transform`](/documentation/QuartzCore/CALayer/transform) object’s `x` from `1` to `2`.

```swift
let animation = CABasicAnimation(keyPath: "transform.scale.x")
animation.fromValue = 1
animation.toValue = 2
```

### Setting Interpolation Values

The [`fromValue`](/documentation/QuartzCore/CABasicAnimation/fromValue), [`byValue`](/documentation/QuartzCore/CABasicAnimation/byValue) and [`toValue`](/documentation/QuartzCore/CABasicAnimation/toValue) properties define the values being interpolated between. All are optional, and no more than two should be non-`nil`. The object type should match the type of the property being animated.

The interpolation values are used as follows:

- Both [`fromValue`](/documentation/QuartzCore/CABasicAnimation/fromValue) and [`toValue`](/documentation/QuartzCore/CABasicAnimation/toValue) are non-`nil`. Interpolates between [`fromValue`](/documentation/QuartzCore/CABasicAnimation/fromValue) and [`toValue`](/documentation/QuartzCore/CABasicAnimation/toValue).
- [`fromValue`](/documentation/QuartzCore/CABasicAnimation/fromValue) and [`byValue`](/documentation/QuartzCore/CABasicAnimation/byValue) are non-`nil`. Interpolates between [`fromValue`](/documentation/QuartzCore/CABasicAnimation/fromValue) and ([`fromValue`](/documentation/QuartzCore/CABasicAnimation/fromValue) + [`byValue`](/documentation/QuartzCore/CABasicAnimation/byValue)).
- [`byValue`](/documentation/QuartzCore/CABasicAnimation/byValue) and [`toValue`](/documentation/QuartzCore/CABasicAnimation/toValue) are non-`nil`. Interpolates between ([`toValue`](/documentation/QuartzCore/CABasicAnimation/toValue) - [`byValue`](/documentation/QuartzCore/CABasicAnimation/byValue)) and [`toValue`](/documentation/QuartzCore/CABasicAnimation/toValue).
- [`fromValue`](/documentation/QuartzCore/CABasicAnimation/fromValue) is non-`nil`. Interpolates between [`fromValue`](/documentation/QuartzCore/CABasicAnimation/fromValue) and the current presentation value of the property.
- [`toValue`](/documentation/QuartzCore/CABasicAnimation/toValue) is non-`nil`. Interpolates between the current value of `keyPath` in the target layer’s presentation layer and [`toValue`](/documentation/QuartzCore/CABasicAnimation/toValue).
- [`byValue`](/documentation/QuartzCore/CABasicAnimation/byValue) is non-`nil`. Interpolates between the current value of `keyPath` in the target layer’s presentation layer and that value plus [`byValue`](/documentation/QuartzCore/CABasicAnimation/byValue).
- All properties are `nil`. Interpolates between the previous value of `keyPath` in the target layer’s presentation layer and the current value of  `keyPath` in the target layer’s presentation layer.

## Topics

### Interpolation values

[`fromValue`](/documentation/QuartzCore/CABasicAnimation/fromValue)

Defines the value the receiver uses to start interpolation.

[`toValue`](/documentation/QuartzCore/CABasicAnimation/toValue)

Defines the value the receiver uses to end interpolation.

[`byValue`](/documentation/QuartzCore/CABasicAnimation/byValue)

Defines the value the receiver uses to perform relative interpolation.



---

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)