简体   繁体   中英

Blur effect on view background

I have this extension, and I was hoping for a blur background, where I can see blur through the view:

import Foundation
import UIKit

extension UIView
{
    func addBlurEffect()
    {
        if !UIAccessibilityIsReduceTransparencyEnabled() {
            self.backgroundColor = UIColor.clear

            let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
            let blurEffectView = UIVisualEffectView(effect: blurEffect)
            blurEffectView.frame = self.bounds
            blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
            self.addSubview(blurEffectView)
        } else {
            self.backgroundColor = UIColor.white
        }

    }
}

Then I use it like this:

let v = UIView(frame: self.view.frame)

v.addBlurEffect()


self.view.addSubview(v)

But I can not see anything under the view?

Add this framework to your project.

Add transparent view over your background and setup blur (view Readme on github) 在此输入图像描述 Preview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM