10月 122017
BackView *bv = [[BackView alloc] initWithFrame:rect]; [self.view addSubview:bv]; - (id)initWithFrame:(CGRect)theFrame { self = [super initWithFrame:theFrame]; self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.8]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.bounds = [[self layer] bounds]; CGRect rect = [[self layer] bounds]; UIBezierPath *outerRectanglePath = [UIBezierPath bezierPathWithRect:rect]; CGRect rect2 = CGRectMake(rect.size.width/2 - 50, rect.size.height/2- 50, 100, 100); UIBezierPath *interRectanglePath = [UIBezierPath bezierPathWithRect:rect2]; [outerRectanglePath appendPath:interRectanglePath]; maskLayer.path = outerRectanglePath.CGPath; maskLayer.position = CGPointMake( rect.size.width / 2.0 , rect.size.height / 2.0 ); maskLayer.fillRule = kCAFillRuleEvenOdd; // maskLayer.fillRule = kCAFillRuleNonZero; [self layer].mask = maskLayer; return self; }