Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

UIView which is added as subview in UIWindow is not visible in the presented view controller

I’m showing a UIView as subview in all view controllers using below function.

func showSubViewInAllScreens() {

    let mySubView = MySubView()

    guard let window = UIApplication.shared.windows.last else { return }

    window.addSubview(mySubView)

}

But if I present a new view controller over my current visible view controller, then this subview is not visible in the presented view controller. The subview stays behind the presented view controller. Can anyone please provide a solution to show this subview over all view controllers which are going to be presented after the subview is displayed ?

We can use "window.bringSubviewToFront(mySubView)" to bring the subview over the presented view controller every time a view controller is being presented. But In my case, I can’t detect when a view controller is going to be presented.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Increase the z position of mySubView‘s layer.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading