如何使用 UIBezierPath 在一个蒙版上绘制多个矩形切口

How to use UIBezierPath to draw multiple rectangle cutouts on top of one mask

我正在尝试创建一个带有树形矩形切口的面具。 UIBezierPath 库可以这样做吗?

for (NSUInteger i = 0;i<3;i++)
{
    NSDictionary *Def = [self.coachMarks objectAtIndex:i];
    CGRect Rect = [[markDef objectForKey:@"rect"] CGRectValue];

    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRect:self.bounds];
    UIBezierPath *cutoutPath = [UIBezierPath bezierPathWithRoundedRect:markRect cornerRadius:self.cutoutRadius];
    [maskPath appendPath:cutoutPath];
    mask.path = maskPath.CGPath;
}

我重新安排了整个库,这是我必须更改的主要方法,以便能够在屏幕上指定的任何位置的图层蒙版顶部绘制多个矩形。要初始化坐标,您需要创建一个数组并将其命名为 coachMarks。这适用于我的示例。

- (void)goToCoachMarkIndexed:(NSUInteger)index {

    markIndex = index;

    NSMutableArray *aBezierPaths = [[NSMutableArray alloc] init];
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRect:self.bounds];
    for (NSUInteger i = 0;i<self.coachMarks.count;i++)
    {
        NSDictionary *markDef = [self.coachMarks objectAtIndex:i];
        CGRect markRect = [[markDef objectForKey:@"rect"] CGRectValue];  
        [aBezierPaths addObject:[UIBezierPath bezierPathWithRoundedRect:markRect cornerRadius:self.cutoutRadius]];
    }
    for(NSUInteger i = 0;i<self.coachMarks.count;i++)
    {
        [maskPath appendPath:[aBezierPaths objectAtIndex:i]];
    }
    mask.path = maskPath.CGPath;
}