CAKeyframeAnimation
CAKeyframeAnimation represents an animation that makes one of a layer's properties pass through several values in turn, or that moves a layer along a path. The values passed through are called keyframes.
As with toValue of CABasicAnimation, the type of the keyframe values is determined by keyPath, so keyPath must be set before values can be.
Inheritance: EventTarget → NSObject → CAAnimation → CAPropertyAnimation → CAKeyframeAnimation
For using it to blink, change colors, and move along a path, see the guide Animation.
Constructor
Creates a keyframe animation with no property specified yet.
Static methods
CAKeyframeAnimation.animationWithKeyPath()
Creates a keyframe animation with a property specified.
Instance properties
Also inherits keyPath from CAPropertyAnimation and the properties of CAAnimation; the commonly used ones are duration, repeatCount, and autoreverses.
| Property | Description |
|---|---|
values | The values passed through in turn |
path | The layer moves along this path. When set, values has no effect |
keyTimes | When each value occurs |
timingFunctions | The timing curve used between each pair of adjacent values |
calculationMode | How it transitions from value to value |
rotationMode | Whether the layer turns when moving along a path |
tensionValues | The tightness of the smooth curve near each value |
continuityValues | The continuity of the smooth curve near each value |
biasValues | The bias of the smooth curve near each value |
Events
Inherits start and stop from CAAnimation.
Examples
const layer = new CALayer();
layer.frame = new CGRect(20, 70, 20, 20);
layer.backgroundColor = 'systemBlue';
const blink = CAKeyframeAnimation.animationWithKeyPath('opacity');
blink.values = [1, 0.2, 1, 0.2, 1];
blink.keyTimes = [0, 0.2, 0.5, 0.7, 1];
blink.duration = 1.5;
layer.addAnimation(blink, { forKey: 'blink' });Effect: Once the layer is shown on screen, it blinks twice over 1.5 seconds: fades, recovers, fades again, recovers again. Not verified in the simulator.
Corresponding iOS API
| ObjC | JS |
|---|---|
[CAKeyframeAnimation animationWithKeyPath:@"position"] | CAKeyframeAnimation.animationWithKeyPath('position') |
keyframe.values = @[@0, @1] | keyframe.values = [0, 1] |
keyframe.path = path.CGPath | keyframe.path = path |
keyframe.calculationMode = kCAAnimationPaced | keyframe.calculationMode = 'paced' |
keyframe.rotationMode = kCAAnimationRotateAuto | keyframe.rotationMode = 'auto' |
See also
- Animating layers: passing through several values, switching values without interpolation, moving along a path
UIBezierPath: the paths used for moving along a pathUIImage: frame-by-frame animation from a set of images