15

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?

Peter Hosey
  • 93,914
  • 14
  • 203
  • 366
Thanks
  • 39,247
  • 69
  • 202
  • 315

4 Answers4

18

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"];

iCode
  • 1,426
  • 1
  • 14
  • 26
Julian
  • 1,191
  • 11
  • 13
  • 2
    Update link to all animatable properties: https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreAnimation_guide/AnimatableProperties/AnimatableProperties.html – Sanjay Chaudhry Jul 10 '13 at 18:50
6

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.

Nathan de Vries
  • 15,391
  • 4
  • 47
  • 55
0

CABasicAnimation animationWithKeyPath Types

When using the CABasicAnimation from the QuartzCore Framework in Objective-C, you have to specify an animationWithKeyPath. This is a long string and is not easily listed in the CABasicAnimation, CAPropertyAnimation, or the CAAnimation 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.

Jean-François Fabre
  • 126,787
  • 22
  • 103
  • 165
Vaibhav Saran
  • 12,548
  • 3
  • 61
  • 73
0

I have used animationWithKeyPath:@"hidden" and animationWithKeyPath:@"strokeEnd". They are not listed in the link below, So I wonder there must be many more.

enRaiser
  • 2,298
  • 1
  • 15
  • 33