RotateCTM使图形消失,Quartz 2D

发布于 2024-11-18 02:18:40 字数 911 浏览 7 评论 0原文

首先,我是一个石英 2d 菜鸟。我有一个饼图,基本上想在东北象限中对角线画一条线,然后水平向右,并有一个标签解释该部分是什么。所以,我有这段绘制对角线的代码。该线向东南延伸。我预计这是基于 iPhone 的原产地位于西北象限。所以我想我可以先将我的 CTM 旋转 3pi/2,然后让相同的代码工作。但是,当我取消注释 CGContextRotateCTM() 行时,我没有得到任何行。我不确定这里发生了什么以及逻辑错误在哪里。谢谢。

   CGPoint circleCenter = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);   
    CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]);
    CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
    CGContextSetLineWidth(context, LINE_WIDTH);
    CGContextBeginPath(context);
//    CGContextRotateCTM(context, 3 * M_PI / 2);
    CGContextMoveToPoint(context, circleCenter.x + self.CircleRadius / 2, circleCenter.y + self.CircleRadius / 2);
    CGContextAddLineToPoint(context, circleCenter.x + self.CircleRadius / 2 + LINE_LENGTH, circleCenter.y + self.CircleRadius / 2 + LINE_LENGTH);
    CGContextStrokePath(context);

First off, I am a quartz 2d noob. I have a pie chart, and basically want to make a line coming out of it diagonally, in the northeast quadrant, then go horizontal to the right, and have a label explaining what that section is. So, I have this code that draws the diagonal line. The line draws to the southeast. I expect that based on the iPhone origin being in the northwest quadrant. So I thought I could rotate my CTM first by 3pi/2, and then have that same code work. However, when I uncomment the CGContextRotateCTM() line, I get no line. I'm not sure what is happening here and where the logic error is. Thanks.

   CGPoint circleCenter = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);   
    CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]);
    CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
    CGContextSetLineWidth(context, LINE_WIDTH);
    CGContextBeginPath(context);
//    CGContextRotateCTM(context, 3 * M_PI / 2);
    CGContextMoveToPoint(context, circleCenter.x + self.CircleRadius / 2, circleCenter.y + self.CircleRadius / 2);
    CGContextAddLineToPoint(context, circleCenter.x + self.CircleRadius / 2 + LINE_LENGTH, circleCenter.y + self.CircleRadius / 2 + LINE_LENGTH);
    CGContextStrokePath(context);

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

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

发布评论

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

评论(1

神经暖 2024-11-25 02:18:40

似乎您正在将线路旋转到视线之外。始终牢记您旋转的中心 - 也许还可以先翻译您的 CTM。

编辑:要进行检查,您可能需要逐步尝试非常小的旋转并观察您的线的走向。

It seems you are rotating your line out of sight. Always keep the center in mind that you rotate around - maybe also translate your CTM first.

Edit: To check, you might want to try very small rotations incrementally and watch where your line goes.

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