Re: Path animation with CGPathAddArcToPoint
Re: Path animation with CGPathAddArcToPoint
- Subject: Re: Path animation with CGPathAddArcToPoint
- From: "Gordon Hughes" <email@hidden>
- Date: Tue, 2 Sep 2008 13:30:46 -0400
Core Animation seems to be one of those subjects that hasn't received a lot
of "air time".
After a considerable amount of experimentation and rebuilds, I found that
the problem was solely with:
followPath.calculationMode = kCAAnimationPaced;
I guess I had gotten lucky with a previous path animation attempt (a
MoveToPoint and EllipseInRect) when I used the paced calculation
mode because it worked. According to the CAKeyframeAnimation Class
Reference, although it's available in OS X 10.5, it's not currently
implemented.
After commenting out the calculationMode property of the path, the layers
animate around the arc, but pause briefly at the start/end point of each
arc, making the animation anything but smooth.
I'd appreciate some suggestions (if there's any to be had). I'd just like
to have my four layers at 12, 9, 6, and 3 o'clock on the path all move
simultaneously and smoothly.
Thanks
On Fri, Aug 29, 2008 at 9:57 AM, Gordon Hughes <email@hidden> wrote:
> In my attempts to animate objects along a circular/elliptical path, I
> naturally turned to CGPathAddEllipseToPoint. Imagine a clock face with four
> equidistant objects located on the path; I want the objects to animate 360
> degrees from their start points. Using the elliptical path, all four
> objects consistently move to the 3 o'clock position, and rotate around the
> path all stacked together before jumping back to their starting positions.
> When I then used CGPathAddArc, it behaved the same way - always starting at
> the 3 o'clock position. I'm guessing that both methods start and end the
> path at that same position.
>
> To get around this, I tried CGPathAddArcToPoint. I know the path is being
> laid out correctly, because when I draw it in a context, I get a perfect
> circle. I know that all my objects are sitting on the path, because I
> verified this with CGPathContainsPoint.
>
>
> In the case of CGPathAddEllipseToPoint and CGPathAddArc is there any way to
> move the starting position of the ellipse/arc to a user-defined point?
>
>
> The offending code from my CGPathAddArcToPoint implementation is below.
> Like I said, it draws a perfect circle, but I can't animate along it. If I
> replace the arcs with a single elliptical path, the animation works, but
> from the wrong starting points.
>
>
>
>
> Thanks in advance.
>
> Gordon
>
>
>
>
> CGPoint arc[8] =
>
> {
>
> CGPointMake(200.0, 300.0),
>
> CGPointMake(300.0, 300.0),
>
> CGPointMake(300.0, 200.0),
>
> CGPointMake(300.0, 100.0),
>
> CGPointMake(200.0, 100.0),
>
> CGPointMake(100.0, 100.0),
>
> CGPointMake(100.0, 200.0),
>
> CGPointMake(100.0, 300.0),
>
> };
>
>
>
> CGMutablePathRef thePath = CGPathCreateMutable();
>
> CGPathMoveToPoint(thePath, NULL, arc[0].x, arc[0].y);
>
> CGPathAddArcToPoint(thePath, NULL, arc[1].x, arc[1].y, arc[2].x, arc[2].y,
> 100.0);
>
> CGPathAddArcToPoint(thePath, NULL, arc[3].x, arc[3].y, arc[4].x, arc[4].y,
> 100.0);
>
> CGPathAddArcToPoint(thePath, NULL, arc[5].x, arc[5].y, arc[6].x, arc[6].y,
> 100.0);
>
> CGPathAddArcToPoint(thePath, NULL, arc[7].x, arc[7].y, arc[0].x, arc[0].y,
> 100.0);
>
> CGPathCloseSubpath(thePath);
>
>
> CAKeyframeAnimation *followPath = [CAKeyframeAnimation
> animationWithKeyPath:@"position"];
>
> followPath.path = thePath;
>
> followPath.delegate = self;
>
> followPath.duration = animationDuration;
>
> followPath.calculationMode = kCAAnimationPaced;
>
> followPath.timingFunction = [CAMediaTimingFunction functionWithName:
> kCAMediaTimingFunctionEaseInEaseOut];
>
> return followPath;
>
>
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden