An object that provides a flexible method of defining animated transformations.
SDKs
- iOS 3.0+
- macOS 10.6+
- Mac Catalyst 13.0+
- tvOS 9.0+
Framework
- Core Animation
Declaration
class CAValueFunction : NSObject
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 CABasic
object with a from
of 0
, a to
of pi
, and a value
of a CAValue
with a function name of rotate
.
Listing 1 shows how you would create such a rotation and apply it to a CALayer
named rotating
.
Animating a layer's rotation
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
and translate
require 3 values, for the individual x
, y
and z
components. When working with these value functions, you specify the animation's from
and to
as arrays.
Listing 2 shows how you could animate a layer's scale from 0
to 1
using a value function.
Animating a layer's scale
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")