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

# CAValueFunction

An object that provides a flexible method of defining animated transformations.

```
class CAValueFunction
```

## Overview

You can use a value function to specify the individual components of an animated transform.

For example, to create a basic animation that rotates a layer from 0° to 180° around its z-axis, you would create a [`CABasicAnimation`](/documentation/QuartzCore/CABasicAnimation) object with a [`fromValue`](/documentation/QuartzCore/CABasicAnimation/fromValue) of `0`, a [`toValue`](/documentation/QuartzCore/CABasicAnimation/toValue) of <doc://com.apple.documentation/documentation/Swift/Float/pi>, and a [`valueFunction`](/documentation/QuartzCore/CAPropertyAnimation/valueFunction) of a [`CAValueFunction`](/documentation/QuartzCore/CAValueFunction) with a function name of [`rotateZ`](/documentation/QuartzCore/CAValueFunctionName/rotateZ).

The following code shows how you would create such a rotation and apply it to a [`CALayer`](/documentation/QuartzCore/CALayer) named `rotatingLayer`.

```swift
let rotateAnimation = CABasicAnimation()
rotateAnimation.valueFunction = CAValueFunction(name: kCAValueFunctionRotateZ)
rotateAnimation.fromValue = 0
rotateAnimation.toValue = Float.pi
rotateAnimation.duration = 3
rotatingLayer.add(rotateAnimation,
                  forKey: "transform")
```

The value functions [`scale`](/documentation/QuartzCore/CAValueFunctionName/scale) and [`translate`](/documentation/QuartzCore/CAValueFunctionName/translate) require 3 values, for the individual `x`, `y` and `z` components. When working with these value functions, you specify the animation’s [`fromValue`](/documentation/QuartzCore/CABasicAnimation/fromValue) and [`toValue`](/documentation/QuartzCore/CABasicAnimation/toValue) as arrays.

The following code shows how you could animate a layer’s scale from `0` to `1` using a value function.

```swift
let scaleAnimation = CABasicAnimation()
scaleAnimation.valueFunction = CAValueFunction(name: kCAValueFunctionScale)
scaleAnimation.fromValue = [0, 0, 0]
scaleAnimation.toValue = [1, 1, 1]
scaleAnimation.duration = 3
scalingLayer.add(scaleAnimation,
                 forKey: "transform")
```

## Topics

### Getting Value Function Properties

[`name`](/documentation/QuartzCore/CAValueFunction/name)

Returns the name of the value function.

### Creating and Initializing Value Functions

[`init(name:)`](/documentation/QuartzCore/CAValueFunction/init(name:))

Returns the value function object identified by the name.

### Constants

[Rotate Value Functions](/documentation/QuartzCore/rotate-value-functions)

Rotate value transform functions construct a 4x4 matrix that represents the corresponding rotation matrix.

[Scale Value Functions](/documentation/QuartzCore/scale-value-functions)

Scale value transform functions construct a 4x4 matrix that represents the corresponding scale matrix.

[Translate Functions](/documentation/QuartzCore/translate-functions)

Translate value transform functions construct a 4x4 matrix that represents the corresponding translate matrix.



---

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)