How can I know the values in CABasicAnimation keyPath

23,351

Solution 1

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.

Solution 2

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.

Share:
23,351
Sailing
Author by

Sailing

Programmer.

Updated on July 09, 2022

Comments

  • Sailing
    Sailing almost 2 years

    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 ?

  • Iulian Onofrei
    Iulian Onofrei about 8 years
    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?
  • Sepehr Behroozi
    Sepehr Behroozi over 5 years
    OMG couldn't Apple just create an enum for this? still can't find "transform.rotation.z" in this method
  • mfaani
    mfaani over 3 years
  • Iulian Onofrei
    Iulian Onofrei over 3 years
    @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.