0

I wish to have a UIImageView that will "float" over the screen, moving through several positions. It quite clear how to code it to go from point A to point B using [UIView animateWithDuration:...]. It even sounds reasonable to add point C in the "completion" block. You know what? I can also add point D to the completion block of point C, but after that, I start getting a spagetti code that I get lost in.

Nowhere could I find a method where you perform some sort of animation-positions-chain, something like an array of CGPoints that run and the UIImageView goes between them one after the other.

Anyone has any idea how to do that?

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
Ohad Regev
  • 5,641
  • 12
  • 60
  • 84

1 Answers1

1

The CAKeyFrameAnimation object is extremely powerful and useful when it comes to animating an object through multiple values at multiple timing points.

The animations rely on key-paths, which luckily, center is one, and accept only NSValue objects for points and NSNumber objects for timing. An example may be found here which animates the scale property. It is meant to be a template for the center property.

Community
  • 1
  • 1
CodaFi
  • 43,043
  • 8
  • 107
  • 153