I want to blur entire screen except one stack view

114 views Asked by At

When my keyboard is showing, text inputs in stack view go up. Now I want to add a blur view behind this stack view.

App has been started:

app has been start

I tried:

let blurEffect = UIBlurEffect(style: .prominent)
blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = view.bounds 
view.addSubview(blurEffectView)

Now text input has been clicked:

Now textinputs has been clicked.

My text input blurred

scene tree

1

There are 1 answers

0
Duncan C On

Your current code is adding a UIVisualEffectView on top of everything in your view controller's view hierarchy. If you want to blur everything but your text view, you'll need to reorganize your view hierarchy so your text view is a top-level subview of the view you want to blur.

Then you'd add your UIVisualEffectView under the text view by calling insertSubview(_:belowSubview siblingSubview:) on the text view's parent view, and passing the text view as the siblingSubview.

That way the UIVisualEffectView will cover up all the other subviews of the text view's parent view, but leave the text view unburied.

Right now, though, your text view is enclosed in 2 different stack views, so you don't have a parent view that will contain all the other contents you want to hide.

If you want to blur the entire stack view that contains your text fields, call insertSubview(_:belowSubview siblingSubview:) on the parent view of your text input stack view, and pass the text input stack view as the siblingSubview.