什么最能解释 CAPropertyAnimationAnimationWithKeyPath: 参数?
我想更好地理解这个参数,
+ (id)animationWithKeyPath:(NSString *)keyPath
他们只是说:“要动画的属性的关键路径。”
在一些示例片段中,我看到如下内容:
CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
CAKeyframeAnimation *animatedIconAnimation = [CAKeyframeAnimation animationWithKeyPath: @"frameOrigin"];
是否有用于确定正确的关键路径参数的列表或经验法则? 即,当我想要对帧的宽度进行动画处理时,我必须遵循什么样的规则才能获得正确的关键路径参数字符串?
I'd like to have a better understanding of this parameter in
+ (id)animationWithKeyPath:(NSString *)keyPath
They just say: "The key path of the property to be animated."
In some example snippets I see things like:
CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
CAKeyframeAnimation *animatedIconAnimation = [CAKeyframeAnimation animationWithKeyPath: @"frameOrigin"];
Is there a list or rule of thumb for determining the correct key path parameter? i.e. when I want to animate the width of a frame, what kind of rules would I have to follow to get to the correct key path parameter string?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
CABasicAnimation 动画WithKeyPath 类型
当在
Objective-C
中使用QuartzCore Framework
中的CABasicAnimation
时,您必须指定一个animationWithKeyPath
。 这是一个很长的字符串,不容易在CABasicAnimation
、CAPropertyAnimation
或CAAnimation
类中列出。 我最终在 Apple 的 iPhone OS 参考库的核心动画编程指南中找到了一个方便的图表。 希望这有助于节省某人的时间,至少对我来说是这样。CABasicAnimation animationWithKeyPath Types
When using the
CABasicAnimation
from theQuartzCore Framework
inObjective-C
, you have to specify ananimationWithKeyPath
. This is a long string and is not easily listed in theCABasicAnimation
,CAPropertyAnimation
, or theCAAnimation
class. I ended up finding a handy chart within the Core Animation Programming guide in Apple’s iPhone OS Reference Library. Hope this helps save someone time, at least it will for me.我使用过animationWithKeyPath:@“hidden”和animationWithKeyPath:@“strikeEnd”。 它们没有在下面的链接中列出,所以我想一定还有更多。
I have used animationWithKeyPath:@"hidden" and animationWithKeyPath:@"strokeEnd". They are not listed in the link below, So I wonder there must be many more.
要了解什么是“关键路径”,您应该了解一些有关键值编码 (KVC) 的知识。 首先,您应该阅读 键值编码基础知识,但最终您应该通读整个键值编码编程指南。 一旦理解了 KVC,其他概念(例如键值观察(KVO))就会更容易理解。
To understand what a "key path" is, you should learn a little about Key-Value Coding (KVC). To start with, you should read Key-Value Coding Fundamentals, but ultimately you should read through the whole Key-Value Coding Programming Guide. Once you understand KVC, other concepts like Key-Value Observing (KVO) will be much easier to understand.
例如,如果您要为 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
为您提供:
[CABasicAnimationanimationWithKeyPath:@"transform.scale.x"];
Well for example if you're animating the layer property of a UIView, then check out CALayer.h - here you can find the property opacity, and the inline doc mentions that it is animatable. Or frameOrigin in NSView.
A bunch of properties are animatable, for iphone:
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreAnimation_guide/AnimatableProperties/AnimatableProperties.html
and mac:
http://developer.apple.com/mac/library/documentation/cocoa/conceptual/CoreAnimation_guide/Articles/AnimProps.html#//apple_ref/doc/uid/TP40005942-SW4
And then there are some extensions:
http://developer.apple.com/mac/library/documentation/cocoa/conceptual/CoreAnimation_guide/Articles/KVCAdditions.html
to give you:
[CABasicAnimation animationWithKeyPath:@"transform.scale.x"];