21

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 ?

Shardul
  • 4,266
  • 3
  • 32
  • 50
Sailing
  • 337
  • 1
  • 2
  • 9

2 Answers2

28

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.

animuson
  • 53,861
  • 28
  • 137
  • 147
Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200
  • 8
    For example, `scale.xy` is not in that list. So it's not complete. Where should I find all key paths or the missing ones? – Iulian Onofrei Mar 23 '16 at 12:22
  • @IulianOnofrei see https://stackoverflow.com/questions/44230796/what-is-the-full-keypath-list-for-cabasicanimation – mfaani Nov 19 '20 at 02:16
  • @Honey, It still doesn't contain `scale.xy`, and maybe the reason is that `scale.yx` works too, so there are a lot of combinations. But nor the answer nor the documentation seem to mention this option of combining them. – Iulian Onofrei Nov 19 '20 at 11:59
14

I'm not sure, but I found a solution that could probably help.

IN SWIFT: Instead of writing a String you can use this:

let shadowAnimation = CABasicAnimation(keyPath: #keyPath(CALayer.shadowRadius))

When you type CALayer. <- autocomplete should give you the available keyPaths.

I hope this helps.

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Ergün Inci
  • 151
  • 1
  • 4