UIBezierPath叠加的相加相减显示

瘦欲@ 提交于 2019-12-05 04:37:49
-(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];
}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!