在 iPad 应用程序中,我想沿中心点为 (768, 512) 且半径为 512 的弧逆时针移动图层。我希望它从 12 点钟开始(即右上角屏幕)并在 6 点钟(右下角)结束。
经过多次尝试和失败后,我得到了代码
CGPoint origin = logo.layer.position;
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = YES;
CGMutablePathRef curvedPath = CGPathCreateMutable();
CGPathMoveToPoint(curvedPath, NULL, origin.x, origin.y);
CGPathAddArc(curvedPath, NULL, 768, 512, 512, -M_PI_2, M_PI_2, YES);
pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);
pathAnimation.duration = 2;
[logo.layer addAnimation:pathAnimation forKey:@"curve"];
但问题是我无法理解起始角度和结束角度参数。为什么要分别使用 -M_PI_2 和 M_PI_2 并将顺时针设置为 YES?
我想我将物体从 90 度逆时针移动到 270 度,因此代码应该是
CGPathAddArc(curvedPath, NULL, 768, 512, 512, -M_PI_2, M_PI_2, YES);
我可能在多个地方都错了,偶然得到了正确的结果。
请纠正我并帮助我理解这两个角度参数:
起始角
The angle (in radians) from the horizontal that determines the starting point of the arc.
结束角
The angle (in radians) from the horizontal that determines the ending point of the arc.
谢谢
狮子座