【问题标题】:AffineTransform a CGPoint仿射变换一个 CGPoint
【发布时间】:2018-03-10 22:49:20
【问题描述】:

我整个上午都在做研究。到目前为止没有运气。我正在尝试围绕我的视图中心旋转一个 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);

它的工作原理很棒。我找到了这篇文章What is the best way to rotate a CGPoint on a grid?,但它没有用。

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

有什么想法吗?

【问题讨论】:

    标签: ios objective-c cgpoint affinetransform


    【解决方案1】:

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

    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
    

    【讨论】:

      猜你喜欢
      • 2010-12-17
      • 1970-01-01
      • 2013-07-04
      • 2013-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多