How can I know the values in CABasicAnimation keyPath

Sailing picture Sailing · Mar 28, 2011 · Viewed 22.7k times · Source

I find some code like this:

CABasicAnimation *anim = [CABasicAnimation animation];
anim.keyPath = @"transform.scale";
anim.fromValue = [NSNumber numberWithFloat:1.0];
anim.toValue = [NSNumber numberWithFloat:0];
anim.removedOnCompletion = NO;
anim.fillMode = kCAFillModeBoth;
anim.delegate = self;
[self.view.layer addAnimation:anim forKey:@"scaleOut"];

and

anim.keyPath = @"transform.rotation.x";

As far as I know, keyPath is a chained method invoke. "transform.scale" for CALayer is aLayer.transform.scale. "transform" is a property of CALayer, "scale" is a 'property' of transform. But property transform in CALayer is CATransform3D.

There is no property named "scale" or "rotation" in CATransform3D.

My Question is: How "scale" and "rotation" are identified by keyPath ?

Answer

Nikolai Ruhe picture Nikolai Ruhe · Mar 28, 2011

Core Animation extends KVC to support direct addressing of fields (or pseudo fields) of some struct-type properties of layers. The feature is described in Core Animation Extensions To Key-Value Coding.