Iphone 我将如何使用CGContext绘制此图

Iphone 我将如何使用CGContext绘制此图,iphone,cgcontext,Iphone,Cgcontext,我想在我看来画这条线来画这条线,我拥有画一条基本线所需要的一切,但我不擅长画,我确实试过这样做,但就是不能让它正确工作。 这是一辆汽车吗?如果您知道两个控制点的位置,请使用 CGContextMoveToPoint(context, x, y); CGContextAddCurveToPoint(context, ...); // Cubic Bézier curve 或 要插入曲线,请使用 CGContextStrokePath(context); 划过曲线。这是一条曲线吗?如果您知道两个

我想在我看来画这条线来画这条线,我拥有画一条基本线所需要的一切,但我不擅长画,我确实试过这样做,但就是不能让它正确工作。

这是一辆汽车吗?如果您知道两个控制点的位置,请使用

CGContextMoveToPoint(context, x, y);
CGContextAddCurveToPoint(context, ...); // Cubic Bézier curve

要插入曲线,请使用

CGContextStrokePath(context);
划过曲线。

这是一条曲线吗?如果您知道两个控制点的位置,请使用

CGContextMoveToPoint(context, x, y);
CGContextAddCurveToPoint(context, ...); // Cubic Bézier curve

要插入曲线,请使用

CGContextStrokePath(context);

绘制曲线。

假设currentBounds是要在其中绘制的区域的边界矩形,则以下代码应绘制与您描述的正弦曲线相似的正弦曲线:

CGContextBeginPath(context);
CGContextMoveToPoint(context, 0.0f, CGRectGetMidY(currentBounds));
CGContextAddCurveToPoint(context, currentBounds.size.width / 5.0f, CGRectGetMidY(currentBounds) - currentBounds.size.width / 5.0f, CGRectGetMidX(currentBounds) - currentBounds.size.width / 5.0f, CGRectGetMidY(currentBounds) - currentBounds.size.width / 5.0f, CGRectGetMidX(currentBounds), CGRectGetMidY(currentBounds));
CGContextAddCurveToPoint(context, CGRectGetMidX(currentBounds) + currentBounds.size.width / 5.0f, CGRectGetMidY(currentBounds) + currentBounds.size.width / 5.0f, currentBounds.size.width - currentBounds.size.width / 5.0f, CGRectGetMidY(currentBounds) + currentBounds.size.width / 5.0f, currentBounds.size.width, CGRectGetMidY(currentBounds));
CGContextClosePath(context);
CGContextStrokePath(context);

假设currentBounds是要在其中绘制的区域的边界矩形,则以下代码应绘制与您描述的正弦曲线类似的正弦曲线:

CGContextBeginPath(context);
CGContextMoveToPoint(context, 0.0f, CGRectGetMidY(currentBounds));
CGContextAddCurveToPoint(context, currentBounds.size.width / 5.0f, CGRectGetMidY(currentBounds) - currentBounds.size.width / 5.0f, CGRectGetMidX(currentBounds) - currentBounds.size.width / 5.0f, CGRectGetMidY(currentBounds) - currentBounds.size.width / 5.0f, CGRectGetMidX(currentBounds), CGRectGetMidY(currentBounds));
CGContextAddCurveToPoint(context, CGRectGetMidX(currentBounds) + currentBounds.size.width / 5.0f, CGRectGetMidY(currentBounds) + currentBounds.size.width / 5.0f, currentBounds.size.width - currentBounds.size.width / 5.0f, CGRectGetMidY(currentBounds) + currentBounds.size.width / 5.0f, currentBounds.size.width, CGRectGetMidY(currentBounds));
CGContextClosePath(context);
CGContextStrokePath(context);

@Jaba:你甚至没有提供数字(宽度、高度、3个突出显示点的位置),任何人如何提供实际点。@Jaba:你甚至没有提供数字(宽度、高度、3个突出显示点的位置),任何人如何提供实际点。