我们在裁减照片时,中间可能要高亮,四周是灰色半透明蒙层,可以如下设置:
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *image = [UIImage imageNamed:@"WechatIMG21"];
[self.view.layer setContents:(id)image.CGImage];
//先遮挡全部
UIView *holeView = [[UIView alloc] initWithFrame:self.view.bounds];
holeView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
[self.view addSubview:holeView];
CAShapeLayer *layer = [CAShapeLayer layer];
//高亮区域
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(50, 250, 200, 200)];
//后面的一个path 为背景path'
[path appendPath:[UIBezierPath bezierPathWithRect:self.view.bounds]];
layer.path = path.CGPath;
//最主要的就是这个模式。fillRule有两种种模式
layer.fillRule = kCAFillRuleEvenOdd;
[holeView.layer setMask:layer];
}
效果如下:
image.png
网友评论