Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want a UIView to cover the whole screen even navigationbar but show its subviews

How to make the UIView to cover the whole screen. I have a black UIView and it's alpha value is 0.5. It has a subview on it as well. Right now the blackView is below the navigationBar. I want it to cover the whole screen including navigationBar.

As you can see in the picture below. The dark view behind the popup view should cover the whole screen. The constraints I am using for the view is simply:

view.addsubView(blackView)

_ = blackview.anchor(view.topAnchor, left: view.leftAnchor, bottom: view.bottomAnchor, right: view.rightAnchor, topConstant: 0, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 0, heightConstant: 0)

The pop up window is a subview of the blackView:

blackView.addSubview(reminderPopUpView) 

How can I do this?

like image 382
Osama Naeem Avatar asked Nov 30 '22 14:11

Osama Naeem


2 Answers

You can simply add your black view as a window subview.

UIApplication.shared.keyWindow?.addSubview(blackView)
like image 117
Savca Marin Avatar answered Dec 03 '22 03:12

Savca Marin


Follow below steps to resolve your problem:

1> Create your UIView with outlet you want to overlay lets call it viewOverLay

2> Use this below code to overlay that view to cover whole screen even navigation bar

self.navigationController?.view.addSubview(self.viewOverLay) 
self.viewOverLay.frame.size.height = (self.navigationController?.view.bounds.height)! 
self.viewOverLay.alpha = 0.0

3> When you want to show it

UIView.animate(withDuration: 0.3) { self.viewOverLay.alpha = 1.0 } 

4> When you want to hide it

UIView.animate(withDuration: 0.3) { self.viewOverLay.alpha = 0.0 }

Please let me know if it works for you.

like image 40
Patrick R Avatar answered Dec 03 '22 05:12

Patrick R