What is the role of the key path in Core Animation?

I'm going to get to know Core Animation and try to implement a simple movement along a curve line. I found a really useful piece of code here

There is a line:

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

Why do we need this property called keyPath? What is his role? The code only works when using the proposed NSString @ position and nothing more. So is this an inline constant string? It doesn’t look like that. I hope you see my confusion. Could you please explain in simple terms how I can manage this KeyPath property?

+4
source share
2 answers
  • KeyPath says which animation attribute will be changed before creating an animation effect.
  • You can use any of the animation properties as a key path.
  • You can find them in the header file (say, CALayer) on which you apply the 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 String constant, this is an attribute name
+3
source

CABasicAnimation and CAKeyframeAnimation inherit from CAPropertyAnimation. Both use the animationWithKeyPath: method.

KeyPath must contain Animation properties . Find them here Link

+2
source

Source: https://habr.com/ru/post/1401559/


All Articles