2016-02-26 95 views
1

问题描述如何设置属性为每个“subUIBezierPath”

我想添加一个“手势解锁”在我的应用程序的功能,但我有一个问题,因为所示的连接形象。我发现一些不必要的线条也可以画出来。事实上,我只需要展示连接每个“按钮”的线。

请检查下面

-> Image click here <-

下面的图片是我在- (void)drawRect:(CGRect)rect

// Main Path 
    UIBezierPath *path = [UIBezierPath bezierPath]; 

    // Rect path 
    UIBezierPath *rectPath = [UIBezierPath bezierPathWithRect:rect]; 
    [path appendPath:rectPath]; 

    // 9 circle path 
    [self.subviews enumerateObjectsUsingBlock:^(PPSingleCircle * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { 

     UIBezierPath *circlePath = [UIBezierPath bezierPathWithOvalInRect:obj.frame]; 
     [path appendPath:circlePath]; 

    }]; 

    // clip the path 
    path.usesEvenOddFillRule = YES; 
    [path addClip]; 

    // add line to each select Views 
    for (int i = 0; i < [self.selectViews count]; i++) { 
     PPSingleCircle *singleView = self.selectViews[i]; 

     if (i == 0) { 
      [path moveToPoint:singleView.center]; 
     }else { 
      [path addLineToPoint:singleView.center]; 
     } 
    } 

    // add line to current point 
    [path addLineToPoint:self.currentPoint]; 

    // set display style 
    [kLineColor setStroke]; 
    path.lineWidth = kLineWidth; 
    path.lineJoinStyle = kCGLineJoinRound; 
    path.lineCapStyle = kCGLineCapRound; 
    [path stroke]; 
+0

您需要将连接线路径作为单独的贝塞尔路径。在你的代码中,你有一个单一的路径,其中包含的圆圈以及它们之间的路径.. – Shripada

+0

@Shripada是的,我已经建立新的路径来存储连接线并设置“lineWidth”= 10,然后我在可能的“主路径”上追加这个“新路径”,在笔画后我发现线宽也是1不是10. –

+0

@Shripada yup,我明白你的意思,它解决了我的问题。谢谢 –

回答

1

代码我解决这个问题,如下

// Main Path 
UIBezierPath *path = [UIBezierPath bezierPath]; 

// Line Path 
UIBezierPath *linePath = [UIBezierPath bezierPath]; 

// Rect path 
UIBezierPath *rectPath = [UIBezierPath bezierPathWithRect:rect]; 
[path appendPath:rectPath]; 

// 9 circle path 
[self.subviews enumerateObjectsUsingBlock:^(PPSingleCircle * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { 
    UIBezierPath *circlePath = [UIBezierPath bezierPathWithOvalInRect:obj.frame]; 
    [path appendPath:circlePath]; 
}]; 

// clip the path 
path.usesEvenOddFillRule = YES; 
[path addClip]; 
// stroke the "Main path" first 
[path stroke]; 

// add line to each select Views 
for (int i = 0; i < [self.selectViews count]; i++) { 

    PPSingleCircle *singleView = self.selectViews[i]; 
    if (i == 0) { 
     [linePath moveToPoint:singleView.center]; 
    }else { 
     [linePath addLineToPoint:singleView.center]; 
    } 
} 

// add line to current point 
PPSingleCircle *view = self.selectViews[0]; 
if (view.status != CircleStatusError) { 
    [linePath addLineToPoint:self.currentPoint]; 
} 

// set display style 
[kLineColor setStroke]; 
linePath.lineWidth = kLineWidth; 
linePath.lineJoinStyle = kCGLineJoinRound; 
linePath.lineCapStyle = kCGLineCapRound; 

// add line path and draw 
[linePath stroke];