Ahd Radwan
Ahd Radwan

Reputation: 1100

Move a view on a circular path

I'am trying to move a UIImageView on a circular path using UIBezierPath , my code works. but my problem with the start point of animation. the imageView start animating from the angle 0 from the path.
How can i change the animation starting point.

 CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height));

CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.duration = FACE_DETECTED_TIME;
animation.timingFunction = [CAMediaTimingFunction functionWithName:@"easeInEaseOut"];
animation.repeatCount = 1;
//    animation.path = path;

UIBezierPath *bezierPath= [UIBezierPath bezierPathWithOvalInRect:self.faceBorderImageView.frame];

animation.path = bezierPath.CGPath ;
 [self.tickImageView.layer addAnimation:animation forKey:@"test" ];

Upvotes: 0

Views: 833

Answers (1)

Duck
Duck

Reputation: 35933

Use an arc instead of circle...

-(UIBezierPath *)createArcWithRadius:(CGFloat)radius withStartAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle {

    UIBezierPath *path=[UIBezierPath bezierPathWithArcCenter:CGPointMake(radius, radius) radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES];

    return path;
}

Upvotes: 2

Related Questions