I want to place a UIView over the entire screen (including the navigation bar). This view will be black with 0.3 opacity. I want to do this to darken out the screen content and push a view on top of this. I am using this code:
UIApplication.sharedApplication().keyWindow?.addSubview(darkView)
This covers the whole screen as expected. However I now want to place another view on top of this dark view. Is there a way to do this? Everything I try just results in the view being under the dark view. Any pointers would be really appreciated! thanks
For SWIFT 3 use this:
Swift 4, Adding a UIViewController as a subview to UIWindow
This code is for adding view controller as a subview, covering the whole window with simple animation.
It's really simple.
You just add another view to
window
! And it will be there, on top of the first view you added. For example, this code adds a black view and a white view:You can also add the new view as a sub view of the first view you added:
Swift 4
Simple!