需要有关如何在 CGPaths 中使用 CGAffineTransform 的示例

发布于 2024-09-30 16:18:33 字数 224 浏览 0 评论 0原文

我不明白如何应用几乎出现在每个 CGPath 方法中的“CGAffineTransform”参数,例如:

void CGPathAddRect (
   CGMutablePathRef path,
   const CGAffineTransform *m,
   CGRect rect
);

假设我想旋转一个矩形路径,我将如何写出这个函数?从哪里获取变换矩阵?

I don't understand how to apply "CGAffineTransform" parameter that appears in practically every CGPath method, e.g.:

void CGPathAddRect (
   CGMutablePathRef path,
   const CGAffineTransform *m,
   CGRect rect
);

Let's say I want to rotate a rect path, how would I write out this function? Where to I get the transform matrix?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海未深 2024-10-07 16:18:33

您可以使用 CGAffineTransformMakeRotation 创建一个绕点 (0, 0) 旋转矩形的 CGAffineTransform。

 CGAffineTransform rotation = CGAffineTransformMakeRotation(M_PI / 4);  // π/4 = 45°
 CGPathAddRect(path, &rotation, CGRectMake(0, 0, 80, 40));

如果您需要它绕任何其他点 (x, y) 旋转,则需要编写 2 个平移来将 (x, y) 移动到 (0, 0) 并返回。

You use use CGAffineTransformMakeRotation to create a CGAffineTransform that rotates the rectangle about the point (0, 0).

 CGAffineTransform rotation = CGAffineTransformMakeRotation(M_PI / 4);  // π/4 = 45°
 CGPathAddRect(path, &rotation, CGRectMake(0, 0, 80, 40));

If you need it to rotate about any other points (x, y), you need to compose 2 translations to move (x, y) to (0, 0) and back.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文