How can I know the values in CABasicAnimation keyPath

我只是一个虾纸丫 提交于 2020-12-28 13:11:39

问题


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 ?


回答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.




回答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.



来源:https://stackoverflow.com/questions/5459673/how-can-i-know-the-values-in-cabasicanimation-keypath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!