我创建一个覆盖的模糊视图与中间明确的矩形剪影。我的代码到目前为止已经取得了相反的结果,即在中间有一个模糊切口的clearView。创建一个明确的剪切模糊视图
我已经改编了以下文章中的步骤,我很感激任何人都可以将我指向正确的方向。
Swift mask of circle layer over UIView
CALayer with transparent hole in it
let blurView = UIVisualEffectView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height))
blurView.effect = UIBlurEffect(style: UIBlurEffectStyle.dark)
let scanLayer = CAShapeLayer()
scanLayer.path = CGPath(rect: scanRect, transform: nil)
view.addSubview(blurView)
blurView.layer.addSublayer(scanLayer)
blurView.layer.mask = scanLayer
我没有任何想法......但最后一行不应该存在blurView.layer.mask = scanLayer – Naresh
使用此https://stackoverflow.com/questions/29647792/swift-how-to-create-a-view-with-a-shape-cropped-in-it请参阅DănuţMihai Florian的回答 – Naresh