什么能最好地解释CAPropertyAnimation animationWithKeyPath:参数?

Tha*_*nks 15 iphone core-animation cakeyframeanimation

我希望能更好地理解这个参数

+ (id)animationWithKeyPath:(NSString *)keyPath
Run Code Online (Sandbox Code Playgroud)

他们只是说:"动画属性的关键路径."

在一些示例片段中,我看到如下内容:

CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];

CAKeyframeAnimation *animatedIconAnimation = [CAKeyframeAnimation animationWithKeyPath: @"frameOrigin"];
Run Code Online (Sandbox Code Playgroud)

是否有用于确定正确密钥路径参数的列表或经验法则?即,当我想设置框架宽度的动画时,我必须遵循什么样的规则才能获得正确的关键路径参数字符串?

Jul*_*ian 18

好吧,例如,如果您正在为UIView的图层属性设置动画,那么请查看CALayer.h - 在这里您可以找到属性不透明度,并且内联文档提到它是可动画的.或NSView中的frameOrigin.

对于iphone,一堆属性是可动画的:

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreAnimation_guide/AnimatableProperties/AnimatableProperties.html

和mac:

http://developer.apple.com/mac/library/documentation/cocoa/conceptual/CoreAnimation_guide/Articles/AnimProps.html#//apple_ref/doc/uid/TP40005942-SW4

然后有一些扩展:

http://developer.apple.com/mac/library/documentation/cocoa/conceptual/CoreAnimation_guide/Articles/KVCAdditions.html

为你带来:

[CABasicAnimation animationWithKeyPath:@"transform.scale.x"];

  • 更新所有可设置动画的属性的链接:https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreAnimation_guide/AnimatableProperties/AnimatableProperties.html (2认同)

Nat*_*ies 6

要了解"关键路径"是什么,您应该了解一下键值编码(KVC).首先,您应该阅读键值编码基础知识,但最终您应该阅读整个键值编码编程指南.一旦理解了KVC,其他概念如Key-Value Observing(KVO)将更容易理解.