我们怎样才能避免额外的贝塞尔曲线?

时间:2017-06-19 11:05:43

标签: ios objective-c uibezierpath cashapelayer cgcontextref

我们可以避免Bezier图中最后一点之后的额外贝塞尔曲线吗?那有什么财产吗?

Please check the screenshot

我们只需要端到端的曲线图,没有额外的曲线。请分享解决方案/建议。更新:请检查以下代码,

- (void)drawRect:(CGRect)rect {
UIBezierPath *line = [UIBezierPath bezierPath];
NSValue *value = points[0];
CGPoint p1 = [value CGPointValue];
[line moveToPoint:p1];if (points.count == 2) {
    value = points[1];
    CGPoint p2 = [value CGPointValue];
    [line addLineToPoint:p2];
    return line;
}

for (NSUInteger i = 1; i < points.count; i++) {
    value = points[i];
    CGPoint p2 = [value CGPointValue];

    CGPoint midPoint = midPointForPoints(p1, p2);
    [line addQuadCurveToPoint:midPoint controlPoint:controlPointForPoints(midPoint, p1)];
    [line addQuadCurveToPoint:p2 controlPoint:controlPointForPoints(midPoint, p2)];

    p1 = p2;
}
 CAShapeLayer *pathLayer = [CAShapeLayer layer];
    pathLayer.frame = self.bounds;
    pathLayer.path = line.CGPath;
    pathLayer.strokeColor = self.color.CGColor;
    pathLayer.fillColor = nil;
    pathLayer.opacity = self.lineAlpha;
    pathLayer.lineWidth = self.lineWidth;
    pathLayer.lineJoin = kCALineJoinBevel;
    pathLayer.lineCap = kCALineCapRound;
 [self.layer addSublayer:pathLayer];}


static CGPoint midPointForPoints(CGPoint p1, CGPoint p2) {
return CGPointMake((p1.x + p2.x) / 2, (p1.y + p2.y) / 2);} 

谢谢!

0 个答案:

没有答案