Set starting point for CGAffineTransform

I am animating a UIView in a circle using CAKeyframeAnimation, which follows CGPathAddEllipseInRect. However, the view always seems to start in the same place, regardless of which frame it was originally placed in. Is there any way to adjust the starting position of the view on the way?

Thank!

CAKeyframeAnimation *myAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
myAnimation.fillMode = kCAFillModeForwards;
myAnimation.repeatCount = 5;
myAnimation.calculationMode = kCAAnimationPaced;
myAnimation.duration = 10.0;

CGMutablePathRef animationPath = CGPathCreateMutable();

CGPathAddEllipseInRect(animationPath, NULL, rect);

myAnimation.path = animationPath;
CGPathRelease(animationPath);

[view.layer addAnimation:myAnimation forKey:@"changeViewLocation"];
+5
source share
2 answers

I don’t think you can set a starting point for CGPathAddEllipseInRect. (At least I was not successful)

: CGPathAddEllipseInRect, : CGPathAddArc! :

CAKeyframeAnimation *myAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
myAnimation.fillMode = kCAFillModeForwards;
myAnimation.repeatCount = 5;
myAnimation.calculationMode = kCAAnimationPaced;
myAnimation.duration = 10.0;

CGMutablePathRef animationPath = CGPathCreateMutable();

NSInteger startVal = M_PI / 2;

//seventh value (end point) must be always 2*M_PI bigger for a full circle rotation
CCGPathAddArc(animationPath, NULL, 100, 100, 100,  startVal, startVal + 2*M_PI, NO); 

myAnimation.path = animationPath;
CGPathRelease(animationPath);

[view.layer addAnimation:myAnimation forKey:@"changeViewLocation"];

, - . startVal, . ( 2 * M_PI).

+1

,

CGFloat startVal = M_PI / 2;

NSInteger startVal = M_PI / 2;

M_PI , . , , .

0

All Articles