Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove BlurView in swift

I have a UIView that contains buttons and labels. When these buttons are pressed, this UIView will become blur using the code below.

@IBOutlet weak var blurView: UIView!
var blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
var blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = blurView.bounds
blurView.addSubview(blurEffectView)

However, I want to remove the blur effect later on. What is the code for removing the blurred UIView?

like image 519
Clarence Avatar asked Nov 03 '15 16:11

Clarence


1 Answers

It's hard to know exactly what is going on in your code, as you've clearly posted a cut up version (the last 4 lines are part of a method somewhere, presumably).

You could do something like this to remove all UIVisualEffectView subviews from your blurView:

for subview in blurView.subviews {
    if subview is UIVisualEffectView {
        subview.removeFromSuperview()
    }
}
like image 109
Charles A. Avatar answered Oct 14 '22 16:10

Charles A.