CAValueFunction
An object that provides a flexible method of defining animated transformations.
Declaration
class CAValueFunctionOverview
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 object with a fromValue of 0, a toValue of pi, and a valueFunction of a CAValueFunction with a function name of rotateZ.
The following code shows how you would create such a rotation and apply it to a CALayer named rotatingLayer.
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 fromValue and toValue as arrays.
The following code shows how you could animate a layer’s scale from 0 to 1 using a value function.
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")