问题描述
我试图添加" 手势解锁"我的应用程序中的功能,但我有一个问题,如附图所示。我发现一些不必要的线也画出来了。事实上,我只需要显示连接每个"按钮"。
的行请查看下面的图片
以下是- (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 :(得分: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];