gpt4 book ai didi

iphone - 理解 CGPathAddArc 时遇到问题

转载 作者:行者123 更新时间:2023-12-03 18:28:32 24 4
gpt4 key购买 nike

在 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.

谢谢

狮子座

最佳答案

0的位置在X轴上,如下所示:

    3*PI/2
|
PI ---|--- 0
|
PI/2

-PI/2 相当于 3PI/2。

您实际上是在同一位置开始轮换(-PI/2、3*PI/2、5*PI/2 等,都是相等的)

您认为的“12 点钟”是 3*PI/2 或 -PI/2...而您向下旋转到“6 点钟”,即 PI/2

关于iphone - 理解 CGPathAddArc 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6857875/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com