UIImage图层蒙版是偏移图像

时间:2017-04-03 04:36:08

标签: ios swift3 uiimage

我有以下代码,旨在通过图层蒙版围绕UIImage的底角。代码工作得很好,只要圆角四舍五入,但是当我这样做时,它会创建一个奇怪的偏移,我无法弄清楚它来自何处。

在这里,没有代码(请注意它是如何在底部排成一行,背后是紫色圆角矩形):

enter image description here

这里是图层蒙版代码:

enter image description here

以下是代码:

//This section sets the corner radius & shadow of the purple rectangle.
totalTankRep.layer.cornerRadius = 8
totalTankRep.clipsToBounds = true
totalTankRep.layer.masksToBounds = false;
totalTankRep.layer.shadowOffset = CGSize(width: 5.0, height: 5.0);
totalTankRep.layer.shadowRadius = 8;
totalTankRep.layer.shadowOpacity = 0.25;


//This defaults the green rectangle to 0 (for the top corners)
oilLevelRep.layer.cornerRadius = 0


//This applies a layer mask that rounds the corners
let maskPath = UIBezierPath(roundedRect: oilLevelRep.bounds, byRoundingCorners: [.bottomLeft, .bottomRight], cornerRadii: CGSize(width: 8.0, height: 0.0))
let maskLayer = CAShapeLayer()
maskLayer.path = maskPath.cgPath
oilLevelRep.layer.mask = maskLayer
view.addSubview(oilLevelRep)

知道这里发生了什么,以及如何解决这个问题?

0 个答案:

没有答案