仿射变换 CGPoint

AffineTransform a CGPoint

我整个上午都在做研究。到目前为止没有运气。我正在尝试围绕我的视图中心旋转 CGPoint。

这是我为 UIBezierPath 所做的:

CGRect bounds = self.bounds; // might want to use CGPathGetPathBoundingBox
CGPoint center = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformTranslate(transform, center.x, center.y);
transform = CGAffineTransformRotate(transform, DEGREES_TO_RADIANS(degreesOfRotation));
transform = CGAffineTransformTranslate(transform, -center.x, -center.y);
currentLayer.path = CGPathCreateCopyByTransformingPath(pathTwo.CGPath, &transform);

效果很好很好。我找到了这个 post What is the best way to rotate a CGPoint on a grid? 但它没有用。

我真的需要一种方法来围绕我的边界中心旋转 CGPoint。

有什么想法吗?

您计算转换的代码是正确的。您需要做的就是将变换应用于该点。

CGRect bounds = self.bounds;
CGPoint center = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformTranslate(transform, center.x, center.y);
transform = CGAffineTransformRotate(transform, DEGREES_TO_RADIANS(degreesOfRotation));
transform = CGAffineTransformTranslate(transform, -center.x, -center.y);

CGPoint point = CGPointMake(bounds.size.width - 10, center.y);  // some point
CGPoint point2 = CGPointApplyAffineTransform(point, transform); // some point rotated about the center of the view