为CGAffineTransform设置Start Point

PF1*_*PF1 5 quartz-graphics cakeyframeanimation cgpath

我使用跟随CGPathAddEllipseInRect的CAKeyframeAnimation围绕圆圈制作UIView.但是,视图似乎总是在同一个地方开始,无论它最初定位在哪个帧中.是否有某种方法可以调整路径上视图的起始位置?

谢谢!

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"];
Run Code Online (Sandbox Code Playgroud)

Gun*_*nds 0

我认为不可能为 CGPathAddEllipseInRect 设置起点。(至少我没有成功)

而不是使用: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"];
Run Code Online (Sandbox Code Playgroud)

将从底部开始顺时针旋转一整圈。更改 startVal 值可更改旋转起始位置。(完整旋转为 2*M_PI)。