美文网首页
带镂空效果的引导页

带镂空效果的引导页

作者: WSGNSLog | 来源:发表于2017-10-25 15:24 被阅读43次

代码不多,demo见github:https://github.com/WSGNSLog/MaskView

    UIWindow *window = [[UIApplication sharedApplication].windows lastObject];
    UIView *maskView = [[UIView alloc] initWithFrame:CGRectMake(0,0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    maskView.backgroundColor = [UIColor blackColor];
    maskView.alpha = 0.4;
    [window addSubview:maskView];
    
    //画一个矩形
    UIBezierPath *bpath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0,0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) cornerRadius:0];
    //画一个矩形,如果想保留矩形以外的部分 , 矩形需要反方向绘制path .
    [bpath appendPath:[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(10, y, 150, 48) cornerRadius:20] bezierPathByReversingPath]];
    //创建一个CAShapeLayer 图层
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = bpath.CGPath;
    
    //添加图层蒙板
    maskView.layer.mask = shapeLayer;
    
    UIImageView *guideImgV = [[UIImageView alloc]initWithFrame:CGRectMake(guideImgV_x, guideImgV_y, guideImgV_w, guideImgV_h)];
    guideImgV.image = [UIImage imageNamed:@"hotLiveGuideImg"];
    [maskView addSubview:guideImgV];

参考:http://www.jianshu.com/p/50c46c72e3dd

相关文章

网友评论

      本文标题:带镂空效果的引导页

      本文链接:https://www.haomeiwen.com/subject/uluqpxtx.html