什么最好地解释了CAPropertyAnimation的animationWithKeyPath参数?

15

我想更好地理解这个参数在

+ (id)animationWithKeyPath:(NSString *)keyPath

他们只是说:“要进行动画处理的属性的关键路径。”

在一些示例片段中,我看到了这样的内容:

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

CAKeyframeAnimation *animatedIconAnimation = [CAKeyframeAnimation animationWithKeyPath: @"frameOrigin"];

有没有一个列表或经验法则来确定正确的关键路径参数?比如,当我想要动画化框架的宽度时,我需要遵循哪些规则才能得到正确的关键路径参数字符串?

4个回答

18

举个例子,如果您正在为UIView的layer属性进行动画处理,则可以查看CALayer.h - 在这里,您可以找到属性opacity,并且内联文档提到它是可动画化的。或者在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"];


2
更新所有可动画属性的链接:https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreAnimation_guide/AnimatableProperties/AnimatableProperties.html - Sanjay Chaudhry

6
为了理解“关键路径”是什么,您应该学习一些关于键值编码(KVC)的知识。首先,您应该阅读键值编码基础,但最终您应该阅读整个键值编码编程指南。一旦您了解了KVC,其他概念如键值观察(KVO)将更容易理解。

0

CABasicAnimation animationWithKeyPath 类型

在使用 Objective-C 中的 QuartzCore Framework 中的 CABasicAnimation 时,您必须指定一个 animationWithKeyPath。这是一个很长的字符串,不容易在 CABasicAnimationCAPropertyAnimationCAAnimation 类中列出。我最终在苹果 iPhone OS 参考库的核心动画编程指南中找到了一个方便的图表。希望这能帮助节省某人的时间,至少对我来说是这样。


0

我使用了animationWithKeyPath:@"hidden"和animationWithKeyPath:@"strokeEnd"。它们在下面的链接中没有列出,所以我想可能还有很多其他的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接