【发布时间】:2013-03-26 00:41:03
【问题描述】:
我正在尝试使 UIImageView 的周围区域变暗,并保留一部分(我用我的蒙版定义)。
现在我正在定义我的蒙版并设置我的 imageView.layer.mask,但是它并没有使图像的其余部分变暗,而是将其完全移除。
我想要的效果类型示例:
我得到的示例:
参考文档提到遮罩使用它的图层 alpha,所以我尝试操纵遮罩的不透明度。但是,这似乎只会影响我想留下的部分的不透明度,而图像的其余部分仍然被完全剪切掉。
谁能指出我做错了什么?谢谢。
这是我的代码:
CAShapeLayer *mask = [CAShapeLayer layer];
GMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, nil, 1052, 448);
CGPathAddLineToPoint(path, nil, 2, 484);
CGPathAddLineToPoint(path, nil, 54, 1263);
CGPathAddLineToPoint(path, nil, 56, 1305);
CGPathAddLineToPoint(path, nil, 380, 1304);
CGPathAddLineToPoint(path, nil, 1050, 1311);
CGPathCloseSubpath(path);
mask.path = path;
CGPathRelease(path);
//mask.opacity = 0.5; //doesn't affect the surrounding portion, only the cut out area.
self.imageView.layer.mask = mask;
【问题讨论】:
-
另一种选择:使用带有遮罩的深色(但不是完全不透明)叠加层来隐藏箭头周围的部分。
标签: ios objective-c calayer mask cashapelayer