1

I'd like to build a random animation of a imageview on iPad. What i manage to build so far is this:

Figure 1

The arrow represents my imageview. it moves to the bounds of its parent view an changes it direction. Actually this is not what i want. Id like to move the view randomly in it's parent view, in curves. And also adjust its heading, like in this figure:

Figure 2

I've no clue how to solve this and in particular how to generate a nice smooth path. Maybe someone has a hint for me.

mightym
  • 191
  • 2
  • 14

3 Answers3

2

Brad Larson answers a question that will give you some insight here: How do I translate parabolically?

Choosing random points is pretty easy and when you add them using a keyframe animation and a path, you get the smoothing you're looking for. You would just need to add the points to the path reference.

You add the path to the keyframe animation according to the link above and then add the animation to the UIImagView's layer with:

[[imageView layer] addAnimation:pathAnimation forKey:@"pathAnimation"];

Best regards.

Community
  • 1
  • 1
Matt Long
  • 24,438
  • 4
  • 73
  • 99
0

Try out with Bezier curves with following
Drawing bezier curves with my finger in iOS?

and CGPathReference

Community
  • 1
  • 1
Harsh Thakur
  • 293
  • 2
  • 11
0

You would actually get quite far by just configuring the calculation mode of the key frame animation to be cubic

positionAniamation.calculationMode = kCAAnimationCubic; // or kCAAnimationCubicPaced

That will cause it to construct cubic splines between the points specified in the values array.

David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205