在圆形路径上移动视图
Move a view on a circular path
我正在尝试使用 UIBezierPath
在圆形路径上移动 UIImageView
,我的代码有效。但是我的动画起点问题。 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" ];
使用圆弧代替圆...
-(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;
}
我正在尝试使用 UIBezierPath
在圆形路径上移动 UIImageView
,我的代码有效。但是我的动画起点问题。 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" ];
使用圆弧代替圆...
-(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;
}