iOS カットアウト マスク マスク

#import "GuideView.h"

#define MLScreenH [UIScreen mainScreen].bounds.size.height
#define MLScreenW [UIScreen mainScreen].bounds.size.width

@implementation GuideView
- (instancetype)init{     self = [super init];     self.frame = CGRectMake(0, 0, MLScreenW, MLScreenH);     [self drawBorderMaskLayer];     自分自身を返します。}




- (void)drawBorderMaskLayer{     //描画     CGRect alphaRect = CGRectMake(10, 100, 100, 100);     CGFloat コーナー半径 = 10;     CAShapeLayer *borderLayer = [CAShapeLayer レイヤー];     borderLayer.frame = self.bounds;     borderLayer.lineWidth = 3;     borderLayer.strokeColor = [UIColor redColor].CGColor;     borderLayer.fillColor = [UIColor clearColor].CGColor;     UIBezierPath *bezierPath=[UIBezierPath bezierPathWithRoundedRect:alphaRect                                                         cornerRadius:cornerRadius];     borderLayer.path = bezierPath.CGPath;     [self.layer insertSublayer:borderLayer atIndex:0];     {//镂空



    





    



    

    
    

        CAShapeLayer *maskLayer = [CAShapeLayer レイヤー];
        maskLayer.frame = self.bounds;
        maskLayer.fillColor = [[UIColor blackColor] colorWithAlphaComponent:0.8].CGColor;
        
        UIBezierPath *bezierPath=[UIBezierPath bezierPathWithRect:self.bounds];
        [bezierPath appendPath:[[UIBezierPath bezierPathWithRoundedRect:alphaRect cornerRadius:cornerRadius] bezierPathByReversingPath]];
        maskLayer.path = bezierPath.CGPath;
        
        [self.layer insertSublayer:maskLayer atIndex:0];
    }
} @
終了

おすすめ

転載: blog.csdn.net/ForeverMyheart/article/details/117085130