self.view.backgroundColor = [UIColor blackColor];
//获取图片
self.imageContents = [UIImage imageNamed:@"原始图片"];
self.maskContents = [UIImage imageNamed:@"maskLayerContents"];
//创建图片layer
self.imageLayer = [CALayer layer];
self.imageLayer.frame = CGRectMake(, , , );
self.imageLayer.contents = (__bridge id)(self.imageContents.CGImage);
[self.view.layer addSublayer:self.imageLayer];
//创建遮住layer
self.maskLayer = [CALayer layer];
self.maskLayer.frame = self.imageLayer.bounds;
self.maskLayer.contents = (__bridge id)(self.maskContents.CGImage);
//黑色表示通过,白色表示不通过(给图片layer提供遮罩)
self.imageLayer.mask = self.maskLayer;
效果图: