[CATransaction begin];
            [CATransaction setAnimationDuration:5];
            CGAffineTransform currentTransform = squareLayer.affineTransform;
            CGFloat angle = M_PI;

            squareLayer.affineTransform = CGAffineTransformRotate(currentTransform, angle);
            [CATransaction commit];


[CATransaction begin];
            [CATransaction setAnimationDuration:5];
            CGAffineTransform currentTransform = squareLayer.affineTransform;
            CGFloat angle = (M_PI * -1);

            squareLayer.affineTransform = CGAffineTransformRotate(currentTransform, angle);
            [CATransaction commit];

我本以为-1会反转方向,但显然不是吗?

最佳答案

角度是相同的。要完整圈,您需要2 * Pi,所以半圈是Pi。如果使用-Pi,它将在同一点结束。

编辑:如果您需要使其顺时针旋转,则可以稍微关闭-Pi。例如,使用-3.141593代替-M_PI。

09-27 17:28