IPhone - How to create a circle for CAKeyframeAnimation?

I am trying to create a keyframe animation that allows me to view an image around a circle. I use CGPathAddCurveToPointto create key frames. The problem is that the shortest (linear) route is always used in the image view.

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

Thanks so much for any help.

+3
source share
2 answers
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 the start point to the end point. If you want to accurately determine the curve, also determining the radius of the circle, you can link to the following link

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

+3

?

  CAKeyframeAnimation* circlePathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"center"];

  CGMutablePathRef circularPath = CGPathCreateMutable();
  CGRect pathRect = ...; // some rect you define. A circle has equal width/height; radius is half the values you specify here
  CGPathAddEllipseInRect(circularPath, NULL, pathRect);
  spinAnimation.path = circularPath;
  CGPathRelease(circularPath);

, - UIView, .

+2

All Articles