开发者

Animate view around circle with arbitrary start point

开发者 https://www.devze.com 2023-02-06 18:00 出处:网络
I am trying to rotate a bunch of CALayers around a ellipse (carousel style) as follows: CGMutablePathRef path = CGPathCreateMutable();

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

CGMutablePathRef path = CGPathCreateMutable();

CGAffineTr开发者_开发知识库ansform 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消