6

I have a layer that will move from point A to point B on a UIBezierPath. I have found a lot of samples those are refers to CAAnimation and UIBezierPath. But I need to move my layer only from specified point to another on bezier path.

enter image description here

Any suggestions would be appreciated.

Thanks

Matt Long
  • 24,438
  • 4
  • 73
  • 99
fyasar
  • 3,996
  • 2
  • 42
  • 55

3 Answers3

4

Hope this will be helpful.

UIBezierPath *trackPath = [UIBezierPath bezierPath];
.
.
.
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
anim.path = trackPath.CGPath;
anim.repeatCount = 1;
anim.duration = 2.0;
[layerToAnimate addAnimation:anim forKey:@"pathGuide"];
Mrug
  • 4,963
  • 2
  • 31
  • 53
3

If your bezier path is a circle or even a half circle, you could just skip the path and instead add the point to a larger square layer. Set the point to be a fixed distance from the center of that larger square layer. Then you can just rotate the larger layer on the z axis around the center whatever number of degrees you need it to move. Seems it would simplify things a bit, though I'm not sure exactly what else you need it to do.

Matt Long
  • 24,438
  • 4
  • 73
  • 99
2

i'd been looking to do something like this and fount this tutorial, it shows how to follow a specific path. It works with a car (a CALayer) and a UIBezierpath as the race track and is solved in this order:

Defining the path the car should follow (in this case your BezierPath) Drawing the black line that defines the track; (N/A) Drawing the white dashed center-line of the track; (N/A) Creating the layer defining the car; (your Layer) Animating the car along the path. (What your asked!)

You can check the reference Post here: http://nachbaur.com/2011/01/07/core-animation-part-4/

Also you can download the source code here: http://cdn5.nachbaur.com/wp-content/uploads/2011/01/CALayerAnimTest.zip?25881d

hope this helps!

regards,

Jorge.

  • thanks for your answer, but thats not i'm looking for. I'm looking to move between two points in bezier path. Not complete path. – fyasar Nov 17 '12 at 00:09
  • Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. Please edit your answer to correct this, then flag your post to request un-deletion – Matt Nov 19 '15 at 21:52