iphone - 使用 Quartz 2D 绘制桥梁

标签 iphone quartz-graphics quartz-2d objective-c-2.0

我正在尝试绘制以下图像:

enter image description here

使用这个 Objective-C 代码:

CGContextSetFillColorWithColor(ctx, [[UIColor redColor] CGColor]);
CGContextMoveToPoint(ctx, position.X - (size.width / 2), position.Y - (size.height / 2));
CGContextAddLineToPoint(ctx, position.X - (size.width / 2), position.Y + (size.height / 2));
CGContextAddLineToPoint(ctx, position.X - (size.width / 4), position.Y + (size.height / 2));
CGContextAddArc(ctx, position.X, position.Y + (size.height / 2), (size.width / 4), -M_PI, M_PI, 0);
CGContextAddLineToPoint(ctx, position.X + (size.width / 2), position.Y + (size.height / 2));
CGContextAddLineToPoint(ctx, position.X + (size.width / 2), position.Y - (size.height / 2));
CGContextFillPath(ctx);

但是这不起作用。我得到这个图像:

enter image description here

图像的宽度为size.width,高度为size.height。 原点是(position.X,position.Y)。该点位于中心,位于 (size.width/2, size.height/2)。

第一个点是左上角,第二个点是左下角。然后继续向右。

这里有一个更好的解释: enter image description here

抱歉我的英语不好。

有什么建议吗?

最佳答案

我更改了这一行:

CGContextAddArc(ctx, position.X, position.Y + (size.height / 2), (size.width / 4), -M_PI, M_PI, 0);

具有以下内容:

CGContextAddArc(ctx, position.X, position.Y + (size.height / 2), (size.width / 4), -M_PI, 0, 0);

现在可以了!!!我对第二个角度有错误。正确的值是 0,而不是 M_PI

关于iphone - 使用 Quartz 2D 绘制桥梁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6403333/

相关文章:

iPhone MkMapView 将中心锁定到用户位置

iOS:提高图像绘制速度

objective-c - 如何更新 NSView 的一部分而不重绘整个 View

python - 将 Quartz 2d python 演示移植到纯 Core Graphics C

iphone - 使用 fetchedresultcontroller 为每个月设置不同的部分

iphone - 单击 "back"按钮时 UINavigationController 应用程序崩溃

ios - UIBezierPath 中的 CGContextAddLineToPoint 和 addLineToPoint 函数有什么区别?

objective-c - 如何使用 Core Graphics 绘制箭头?

iphone - 如何在 PDF 中输出欧元符号

iphone - 为响应触摸事件的旋转轮设置动画的最佳方式