Tarvo Mäesepp Tarvo Mäesepp - 29 days ago 9
Swift Question

Adding UIVisualEffectView also over tab bar

I am trying to create modal popup with

UIVisualEffectView
as it's background. I want the
UIVisualEffectView
to be over the tab bar but I do not see the way to achieve it.

This is what I do but this is not the output I want:

var visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .light))
visualEffectView.frame = self.view.bounds
tabBarController?.view.addSubview(visualEffectView)

//Also tried like this
self.view.window?.addSubview(visualEffectView)


This is pretty much what I am looking for:

enter image description here

So my question is, how should I add the
UIVisualEffectView
to be over tab bar also as a subView. I know I could make another viewController and present it as
.OverCurrentContext
but this is not a solution for me.

Answer Source

I reproduced the problem adding the visualEffectView to UITabBarController's main view. For non-translucent tab bar view controller views are not extended under it, so the height is shorter than you need.

To fix the problem change

visualEffectView.frame = self.view.bounds

to:

visualEffectView.frame = self.tabBarController!.view.bounds