0

I have a UIVisualEffectView that I am trying to set to nil upon viewdidload

What am I doing wrong?

@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

}
Cameron
  • 185
  • 2
  • 11
  • print(self.visualEffectView.effect) and see if it is nil – 3stud1ant3 Sep 09 '17 at 02:03
  • @3stud1ant3 when I print it out it is not nil – Cameron Sep 09 '17 at 02:05
  • I tried this and it gives me nil , I have tried this code: @IBOutlet weak var myVisualEffectView: UIVisualEffectView! var effect: UIVisualEffect! override func viewDidLoad() { super.viewDidLoad() effect = myVisualEffectView.effect print(effect) self.myVisualEffectView.effect = nil print(self.myVisualEffectView.effect) } , first print(effect) prints the UIBlur effect instance and second print prints nil – 3stud1ant3 Sep 09 '17 at 02:15
  • OK, I can make mine print nil but for some reason the visualeffectview still shows up – Cameron Sep 09 '17 at 02:19
  • You want to remove the effect and then again use it at other place or you just simply want to remove it? – 3stud1ant3 Sep 09 '17 at 02:21
  • remove and then use it again when a certain button is clicked – Cameron Sep 09 '17 at 02:23
  • I have used blureffect of visualeffect but you can use any. Please change it. see my answer – Jitendra Modi Sep 09 '17 at 05:15

1 Answers1

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()
                }
            }
        }
Jitendra Modi
  • 2,344
  • 12
  • 34