UIBezierPath叠加的相加相减显示

-(void)addBlankFrames:(NSArray<__kindof NSValue *> *)frames {
    UIBezierPath *path = self.blankPath?:[UIBezierPath bezierPath];
    CGRect oldRect = CGRectZero;
    for (NSValue *value in frames) {
        CGRect frame = [value CGRectValue];
        UIBezierPath *p = [UIBezierPath bezierPathWithRect:frame];
        if (oldRect.size.width > 0 && oldRect.size.height > 0) {
            [p appendPath:[[UIBezierPath bezierPathWithRect:CGRectIntersection(frame, oldRect)] bezierPathByReversingPath]];
        }
        [path appendPath:p];

        oldRect = frame;
    }
    [path closePath];
    self.blankPath = path;
    UIBezierPath *showPath = [UIBezierPath bezierPathWithRect:self.blackLayer.bounds];
    [showPath appendPath:[self.blankPath bezierPathByReversingPath]];
    [self.blackLayer setPath:showPath.CGPath];
}

-(void)hideNoBlankFrames:(NSArray<__kindof NSValue*> *)frames {
    UIBezierPath *path = self.blankPath?:[UIBezierPath bezierPath];
    for (NSValue *value in frames) {
        CGRect frame = [value CGRectValue];
        UIBezierPath *p = [UIBezierPath bezierPathWithRect:frame];
        [path appendPath:p];
        [path appendPath:p];
    }
    [path closePath];
    self.blankPath = path;
    UIBezierPath *showPath = [UIBezierPath bezierPathWithRect:self.blackLayer.bounds];
    [showPath appendPath:[self.blankPath bezierPathByReversingPath]];
    [self.blackLayer setPath:showPath.CGPath];
}

 

posted @ 2019-11-21 16:21  雨筱逸悠  阅读(543)  评论(0编辑  收藏  举报