0

我有两个 CGPoints。我需要画一条从一个到另一个的曲线。我怎么画它?核心图形还是贝塞尔路径?如果是这样,我需要一些指导。提前谢谢你的帮助。

4

1 回答 1

2

使用UIBezierPath或 CGPath 。 UIBezierPathNSBezierPath在 OS X 上一样工作。在视图的 drawRect: 方法中,声明对象

UIBezierPath *aPath = [UIBezierPath bezierPath];

然后开始第一点。

[aPath moveToPoint: startPoint];

接下来添加带有控制点的曲线段。这是确定控制点需要位于何处的困难部分。

有两种。三次曲线

[aPath addCurveToPoint: aDestinationPoint controlPoint1: aControlPoint controlPoint2: anotherControlPoint];

二次曲线

[aPath addQuadCurveToPoint:aDestinationPoint  controlPoint: aLonelyControlPoint];

最后,在 UIColor(Mac 上的 NSColor)上调用 set 方法。然后描边或填充路径。

[aPath stroke];

您可能还想设置笔触宽度。

请记住,在程序上绘图是从前到后的,如果您想在下一个填充或描边的绘图命令之前在不同的颜色上设置不同的颜色调用

事件的 CG 版本类似但更复杂。

http://developer.apple.com/library/ios/documentation/2ddrawing/conceptual/drawingprintingios/BezierPaths/BezierPaths.html

于 2013-05-27T09:23:53.910 回答