Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate view around circle with arbitrary start point

I am trying to rotate a bunch of CALayers around a ellipse (carousel style) as follows:

CGMutablePathRef path = CGPathCreateMutable();

CGAffineTransform squash = CGAffineTransformMakeScale(1.1, 0.8);
CGAffineTransform squashInv = CGAffineTransformInvert(squash);
CGPoint c = CGPointApplyAffineTransform(centre, squashInv);

CGPathAddArc(path, &squash, c.x, c.y, radius, 2.0*M_PI, 0.0, YES);

CAKeyframeAnimation *pathAni = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAni.path = path;
pathAni.duration = 14.0;
pathAni.calculationMode = kCAAnimationPaced;
CFRelease(path);

which works great except each view always starts animating at the 3 o'clock position. Now I'm trying to get my head around starting each view at an arbitrary point along the ellipse and would like some suggestions.

(I've tried CGMoveArcToPoint and also tried to rotate the circle with CGAffineTransformMakeRotate on the path but to no avail)

Thanks for your time

like image 233
Brett Avatar asked Dec 06 '25 13:12

Brett


1 Answers

Have you tried the timeOffset property (part of the CAMediaTiming protocol)?

The timing protocol provides the means of starting an animation a certain number of seconds into its duration using two properties: beginTime and timeOffset. The beginTime specifies the number of seconds into the duration the animation should start and is scaled to the timespace of the animation's layer. The timeOffset specifies an additional offset, but is stated in the local active time. Both values are combined to determine the final starting offset.

like image 116
Benedict Cohen Avatar answered Dec 09 '25 03:12

Benedict Cohen