Skip to content

CAPropertyAnimation ​

CAPropertyAnimation represents an animation that changes one property of a layer. It determines which property the animation changes, and so determines what type the from value, to value, and keyframe values must have.

It is the common parent class of CABasicAnimation, CAKeyframeAnimation, and CASpringAnimation.

Inheritance: EventTarget → NSObject → CAAnimation → CAPropertyAnimation

Constructor ​

Cannot be created with new. Create one through a subclass, for example CABasicAnimation.animationWithKeyPath().

Instance properties ​

Also inherits the properties of CAAnimation; the commonly used ones are duration, repeatCount, and timingFunction.

PropertyDescription
keyPathWhich property the animation changes

Events ​

Inherits start and stop from CAAnimation.

Animatable properties ​

The names keyPath accepts, and the value type for each name:

keyPathValue typeApplies to
'opacity', 'cornerRadius', 'borderWidth', 'shadowOpacity', 'shadowRadius', 'zPosition'NumberAll layers
'position'CGPointAll layers
'bounds'CGRectAll layers
'shadowOffset'CGSizeAll layers
'backgroundColor', 'borderColor', 'shadowColor'ColorAll layers
'contents'UIImageAll layers
'transform', 'sublayerTransform'CATransform3DAll layers
'transform.rotation', 'transform.rotation.x', 'transform.rotation.y', 'transform.rotation.z'Number; the angle rotated, in radiansAll layers
'transform.scale', 'transform.scale.x', 'transform.scale.y', 'transform.scale.z'Number; a multipleAll layers
'transform.translation.x', 'transform.translation.y', 'transform.translation.z'Number; the translation, in ptAll layers
'transform.translation'CGSize: width is the translation in the x direction and height in the y direction, in ptAll layers
'lineWidth', 'miterLimit', 'strokeStart', 'strokeEnd', 'lineDashPhase'NumberCAShapeLayer
'fillColor', 'strokeColor'ColorCAShapeLayer
'path'UIBezierPathCAShapeLayer
'startPoint', 'endPoint'CGPointCAGradientLayer

A few frequently asked cases:

  • frame cannot be animated. To move a layer use 'position' (the coordinates of its center); to change its size use 'bounds'.
  • To only rotate, scale, or translate, use a component of transform. Names such as 'transform.rotation.z' change only one component of the transform; the from and to values are each a single number, so you don't need to build a whole matrix. 'transform.rotation' is the same as 'transform.rotation.z': both rotate within the plane of the screen. 'transform.scale' changes the multiple in all three directions at once. For a full turn, write toValue = 2 * Math.PI. The on-screen effect is not verified in the simulator.
  • The value of the whole 'transform' is a CATransform3D. When writing, you can also pass a plain object with all 16 fields; the rules are the same as for the layer's transform.
  • Gradient colors cannot be animated. colors and locations are not in the table.
  • The types of the from value, to value, and so on must match keyPath. So keyPath must be set before the values.
  • Numbers must be written as numbers, not strings. A string in any of these value positions is always treated as a color. fade.toValue = '0.5' is not taken as 0.5.

Corresponding iOS API ​

ObjCJS
anim.keyPath = @"opacity"anim.keyPath = 'opacity'

See also ​