투각 효과가 있는 안내 페이지

1275 단어
코드가 많지 않습니다. 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

좋은 웹페이지 즐겨찾기