Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS CALayer遮罩-始终为深色边框?_Ios_Calayer_Mask - Fatal编程技术网

iOS CALayer遮罩-始终为深色边框?

iOS CALayer遮罩-始终为深色边框?,ios,calayer,mask,Ios,Calayer,Mask,我正在尝试使用以下代码为UIView创建一个简单的掩码: CAShapeLayer *mask = [CAShapeLayer layer]; CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, nil, 0, 0); CGPathAddLineToPoint(path, nil, 80, 80); CGPathAddLineToPoint(path, nil, 0, 80); CGPathCloseSu

我正在尝试使用以下代码为UIView创建一个简单的掩码:

CAShapeLayer *mask = [CAShapeLayer layer];

CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, nil, 0, 0);
CGPathAddLineToPoint(path, nil, 80, 80);
CGPathAddLineToPoint(path, nil, 0, 80);
CGPathCloseSubpath(path);

mask.path = path;
CGPathRelease(path);

self.layer.mask = mask;
除了遮罩周围的黑色1像素边框外,遮罩工作正常。对我来说,最好的解释方法是建议忽略抗锯齿,任何不完全透明的像素都被视为不透明

我甚至试着用我想要的形状创建一个透明的.PNG,但是这个黑色的边框仍然出现


有什么建议吗?

谢谢你的回复。它不是一个规则的矩形,它是一个三角形,我希望在整个应用程序中使用这种方法,使用不同的形状。不管怎样,被屏蔽的视图的大小是多少?如果不设置遮罩,而是将形状层添加为子层(最好使用与其他内容形成良好对比的颜色),效果如何?