在圆形路径上移动视图

时间:2015-09-02 09:36:26

标签: ios objective-c animation uibezierpath

我正在尝试使用UIImageView在圆形路径上移动UIBezierPath,我的代码可以使用。但我的动画起点问题。 imageView从路径的角度0开始制作动画 如何更改动画起点。

 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" ];

1 个答案:

答案 0 :(得分:2)

使用弧而不是圆圈......

-(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;
}