现实中经常会遇到如图需求:
代码如下:复制之余也要自己理解下原理,做到举一反三,深谙其道。
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
blurEffectAction()
}
func blurEffectAction() {
let image = UIImageView(image: UIImage(named: "sexy"))
image.frame = UIScreen.main.bounds
//image.contentMode = .scaleAspectFit
self.view.addSubview(image)
//UIVisualEffectView--UIView类型,相当于在self.view上层又添加一个view
let blurEffect = UIBlurEffect(style: .dark)
let overlay = UIVisualEffectView(effect: blurEffect)
overlay.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
//CAShapeLayer起渲染作用
let maskLayer = CAShapeLayer()
maskLayer.frame = CGRect(x: 0, y: 0, width: UIScreen.main.