0

I'm trying to create a View that has a UIBezierPath on it. This works now. I would like to place UIImages (random number of images) on that UIBezierPath and animate them on request all to the next step or the previous step. All images at once and all to the same direction.

Have been looking at all documentation now and i can't figure it out.

So hopefully somebody can help me or point me in the right direction.

I think you can compare it to some racecars that are chasing eachother, not gaining eachother and all starting on different locations. I want to move them to a next point by touch, so no loops needed.

stackr
  • 2,742
  • 27
  • 44

3 Answers3

2

Take a look at this tutorial. Relevant code:

//create the image layer
CALayer *car = [CALayer layer];
car.bounds = CGRectMake(0, 0, 44.0, 20.0);
car.position = CGPointMake(160, 25);
car.contents = (id)([UIImage imageNamed:@"carmodel.png"].CGImage);
[self.view.layer addSublayer:car];

// animate it
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
anim.path = trackPath.CGPath;
anim.rotationMode = kCAAnimationRotateAuto;
anim.repeatCount = HUGE_VALF;
anim.duration = 8.0;
[car addAnimation:anim forKey:@"race"];

Add this animation for all layers(images).

tipycalFlow
  • 7,594
  • 4
  • 34
  • 45
1

You'll probably have to construct an array of UIBezierPaths, one for each segment. Keep track of where each UIImage is, and animate it moving along the appropriate segment.

This only works if you have discrete steps. It's a shame that you can't use the values property to restrict movement to a portion of the total path... but that gets ignored. It should be possible to subclass CAMediaTimingFunction to change its output range to something other than 0 to 1, but all the important pieces of that are private.

Cowirrie
  • 7,218
  • 1
  • 29
  • 42
0

You can use strokeStart and strokeEnd property to get a value from 0 to 1 in order to get your objects positioned over the path.

Naveed Abbas
  • 1,157
  • 1
  • 14
  • 37