您的位置:首页 > 移动开发 > IOS开发

iOS 利用mask layer 使view中扣掉一块露出下边的view

2015-11-26 16:58 751 查看
#define SCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width 

#define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height 

 

- (void)addMask{ 

    UIButton * _maskButton = [[UIButton alloc] init]; 

    [_maskButton setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; 

    [_maskButton setBackgroundColor:[UIColor colorWithWhite:0 alpha:0.7]];      [self.view addSubview:_maskButton]; 

             

            //create path 

            UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; 

         

            // MARK: circlePath 

            [path appendPath:[UIBezierPath bezierPathWithArcCenter:CGPointMake(SCREEN_WIDTH / 2, 200) radius:100 startAngle:0 endAngle:2*M_PI clockwise:NO]]; 

             

            // MARK: roundRectanglePath 

            [path appendPath:[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(20, 400, SCREEN_WIDTH - 22 * 20, 100) cornerRadius:15] bezierPathByReversingPath]]; 

             

            CAShapeLayer *shapeLayer = [CAShapeLayer layer]; 

             

            shapeLayer.path = path.CGPath; 

             

            [_maskButton.layer setMask:shapeLayer]; 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: