UIVisualEffectView未设置为nil

时间:2017-09-09 01:54:00

标签: ios swift xcode uiblureffect

我有一个UIVisualEffectView,我试图在viewdidload上设置为nil

我做错了什么?

@IBOutlet var popUpView: UIView!

@IBOutlet weak var visualEffectView: UIVisualEffectView!

var effect: UIVisualEffect!

@IBOutlet weak var headerLabel: UILabel!

override func viewDidLoad() {
    super.viewDidLoad()

    effect = visualEffectView.effect
    self.visualEffectView.effect = nil
    popUpView.layer.cornerRadius = 5

}

1 个答案:

答案 0 :(得分:0)

    See my answer


    var blurEffect = UIBlurEffect()
    var blurview : UIView = UIView()

    //HERE pass view as bringtofront from blurview and pass view where you want to set blurview upon
        func add_blur_view(v : UIView, view_bring_to_front: UIView) {
            blurEffect  = UIBlurEffect(style: UIBlurEffectStyle.dark)
            let blurEffectView = UIVisualEffectView(effect: blurEffect)
            blurEffectView.frame = v.bounds
            blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
            v.addSubview(blurEffectView)
            v.bringSubview(toFront: view_bring_to_front)
        }

        func remove_blur_view(v : UIView)  {
            for subview in v.subviews {
                if subview is UIVisualEffectView {
                    subview.removeFromSuperview()
                }
            }
        }