Swift UIView 鏤空
func showGuidage() {
? ? ? ? // 鏤空
? ? ? ? //透明區(qū)域
? ? ? ? let nRect = CGRect.init(x: zScaleDev(iPhoneX: 15, iPadX: 54), y: zScaleDev(iPhoneX: 0, iPadX: 0), width: zScaleDev(iPhoneX: 345, iPadX: 727), height: zScaleDev(iPhoneX: 160, iPadX: 185))
? ? ? ? // 不能直接加在最底層viewController.view上面,會(huì)黑掉 后面沒東西顯示了
? ? ? ? let backgroundView = UIView()
? ? ? ? backgroundView.frame = CGRect.init(x: (zScreenW - zScaleDev(iPhoneX: 375, iPadX: 834)) / 2 , y: zNavBarH, width: zScaleDev(iPhoneX: 375, iPadX: 834), height:? zScaleDev(iPhoneX: 970, iPadX: 1112))
? ? ? ? view.addSubview(backgroundView)
? ? ? ? let maskLayer = CAShapeLayer()
? ? ? ? maskLayer.fillRule = CAShapeLayerFillRule.evenOdd //? 奇偶層顯示規(guī)則
? ? ? ? maskLayer.fillColor = UIColor.init(red: 0, green: 0, blue: 0, alpha: 0.6).cgColor
? ? ? ? maskLayer.opacity = 0.8
? ? ? ? backgroundView.layer.addSublayer(maskLayer)
? ? ? ? let basicPath = UIBezierPath.init(roundedRect: backgroundView.bounds, cornerRadius: 0) // 底層
? ? ? ? let maskPath = UIBezierPath.init(roundedRect: nRect, cornerRadius: zScale(x: 14))
? ? ? ? basicPath.append(maskPath) // 重疊
? ? ? ? basicPath.usesEvenOddFillRule = true
? ? ? ? maskLayer.path = basicPath.cgPath
? ? }