4

I'm getting acquanted with Core Animation and trying to implement simple movement along a curve line. i've found really helpful piece of code here

There is a line there:

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];

Why do we need this property named keyPath? What is its role? The code works only if use the proposed NSString @"position" and nothing else. So is it a built-in constant string? It doesn't look so. Hope you see my confusion. Can you please explain in plain language how do i manage this keyPath property?

Community
  • 1
  • 1
Andrey Chernukha
  • 21,004
  • 16
  • 95
  • 160

2 Answers2

3
  • KeyPath says which animatable attribute is going to modified to create animation effect
  • You can use any of the animatable property as keypath
  • You can find them in the header file(say CALayer) on which you apply animation
 /* The position in the superlayer that the anchor point of the layer's
  bounds rect is aligned to. Defaults to the zero point. **Animatable**. */
   @property CGPoint position;
  • Not a constant String , it is attribute name
Vignesh
  • 10,077
  • 2
  • 33
  • 70
2

CABasicAnimation and CAKeyframeAnimation are inherited from CAPropertyAnimation. Both use its animationWithKeyPath: method.

KeyPath has to contain Animatable Properties. Find them here Link

SVGreg
  • 2,252
  • 1
  • 13
  • 17