且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iPhone - 如何使一个CAKeyframeAnimation一个圆圈路径?

更新时间:2023-02-09 20:32:00

  CGMutablePathRef路径= CGPathCreateMutable();
CGPathMoveToPoint(路径,NULL,startPoint.x,startPoint.y);
CGPathAddQuadCurveToPoint(路径,NULL,middlePoint.x,middlePoint.y,endPoint.x,endPoint.y);CAKeyframeAnimation * pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@位置];
pathAnimation.removedOnCompletion = NO;
pathAnimation.path =路径;
[pathAnimation setCalculationMode:kCAAnimationCubic];
[pathAnimation setFillMode:kCAFillModeForwards];
pathAnimation.duration = 2.0;[viewTobemoved.layer addAnimation:pathAnimation forKey:无];

此动画只使用一个贝塞尔点,使软圈从起始点到结束点时,若你想用也定义你可以参考以下链接

圆的半径准确定义曲线

http://blog.shoguniphicus.com/2011/05/19/keyframe-animation-ios-cakeyframeanimation-objective-c/

I'm trying to make an key frame animation that lets a image view fly around a circle. I'm using CGPathAddCurveToPoint to make the key frame points. The problem is that the image view always uses the shortest (linear) route.

I would like to have some kind of function that builds a circle path for a given radius.

Thanks a lot for any help.

CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, startPoint.x, startPoint.y);
CGPathAddQuadCurveToPoint(path, NULL,middlePoint.x, middlePoint.y,endPoint.x,endPoint.y);

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.removedOnCompletion = NO;
pathAnimation.path = path;
[pathAnimation setCalculationMode:kCAAnimationCubic];
[pathAnimation setFillMode:kCAFillModeForwards];
pathAnimation.duration = 2.0;

[viewTobemoved.layer addAnimation:pathAnimation forKey:nil];

This animation uses only one bezier point and makes a soft circle from beginning point to end point.If you want to define the curve exactly by also defining the radius of the circle you can refer to the following link

http://blog.shoguniphicus.com/2011/05/19/keyframe-animation-ios-cakeyframeanimation-objective-c/