我想在我的视图中绘制这条线来绘制这条线,我拥有制作基本线所需的一切,但我不擅长绘画,我确实尝试过这样做,但无法让它正常工作。
问问题
3254 次
2 回答
2
这是贝塞尔曲线吗?如果您知道两个控制点的位置,请使用
CGContextMoveToPoint(context, x, y);
CGContextAddCurveToPoint(context, ...); // Cubic Bézier curve
或者
CGContextMoveToPoint(context, x, y);
CGContextAddQuadCurveToPoint(context, ...); // Quadratic Bézier curve
插入曲线,然后使用
CGContextStrokePath(context);
描边曲线。
于 2010-03-02T11:07:04.793 回答
2
下面的代码应该像您描述的那样绘制一条正弦曲线,假设 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);
于 2010-03-03T03:08:36.993 回答