?let?path =UIBezierPath(rect:CGRect(x:0,y:0,width:ScreenWidth,height:ScreenHeight))
//鏤空區(qū)域
let?rect :CGRect=CGRect(x:16~,y: y,width:ScreenWidth-32~,height: height)
//圓角大小
?let?cornerRadius =12~
let?topLeft =CGPoint(x:CGRectGetMinX(rect) ,y:CGRectGetMinY(rect))
let?bottomLeft =CGPoint(x:CGRectGetMinX(rect),y:CGRectGetMaxY(rect))
let?bottomRight =CGPoint(x:CGRectGetMaxX(rect),y:CGRectGetMaxY(rect))
let?topRight =CGPoint(x:CGRectGetMaxX(rect),y:CGRectGetMinY(rect))
//逆時針繪制圓角矩形
path.move(to:CGPoint(x: topLeft.x+ cornerRadius,y: topLeft.y))
path.addArc(withCenter:CGPoint(x: topLeft.x+ cornerRadius,y: topLeft.y+ cornerRadius),radius: cornerRadius,startAngle:CGFloat(-Double.pi/2),endAngle:CGFloat(Double.pi),clockwise:false)
path.addLine(to:CGPoint(x: bottomLeft.x,y: bottomLeft.y- cornerRadius))
path.addArc(withCenter:CGPoint(x: bottomLeft.x+ cornerRadius,y: bottomLeft.y- cornerRadius),radius: cornerRadius,startAngle:CGFloat(Double.pi),endAngle:CGFloat(Double.pi/2),clockwise:false)
path.addLine(to:CGPoint(x: bottomRight.x- cornerRadius,y: bottomRight.y))
path.addArc(withCenter:CGPoint(x: bottomRight.x- cornerRadius,y: bottomRight.y- cornerRadius),radius: cornerRadius,startAngle:CGFloat(Double.pi/2),endAngle:0,clockwise:false)
path.addLine(to:CGPoint(x: topRight.x,y: topRight.y+ cornerRadius))
path.addArc(withCenter:CGPoint(x: topRight.x- cornerRadius,y: topRight.y+ cornerRadius),radius: cornerRadius,startAngle:0,endAngle:CGFloat(-Double.pi/2),clockwise:false)
path.close()
//新建 shapeLayer
let?shaperLayer =CAShapeLayer()
//設(shè)置 shaperLayer 的 path 為 path
shaperLayer.path= path.cgPath
//將目標(biāo) View 扔罪,layer的 mask 設(shè)置為shaperLayer(superView 為要添加鏤空的目標(biāo) view)
superView.layer.mask= shaperLayer