I want to display, above any other views, even the navigation bar, a kind of \"pop-up\" view that looks like this:
You need to add a subview to the first window with the UITextEffectsWindow type. To the first, because custom keyboards add their UITextEffectsWindow, and if you add a subview to it this won't work correctly. Also, you cannot add a subview to the last window because the keyboard, for example, is also a window and you can`t present from the keyboard window. So the best solution I found is to add subview (or even push view controller) to the first window with UITextEffectsWindow type, this window covers accessory view, navbar - everything.
let myView = MyView()
myView.frame = UIScreen.main.bounds
guard let textEffectsWindow = NSClassFromString("UITextEffectsWindow") else { return }
let window = UIApplication.shared.windows.first { window in
window.isKind(of: textEffectsWindow)
}
window?.rootViewController?.view.addSubview(myView)
[self.navigationController.view addSubview:overlayView];
is what you really want
Swift versions for the checked response :
Swift 4 :
let view = UIView()
view.frame = UIApplication.shared.keyWindow!.frame
UIApplication.shared.keyWindow!.addSubview(view)
Swift 3.1 :
let view = UIView()
view.frame = UIApplication.sharedApplication().keyWindow!.frame
UIApplication.sharedApplication().keyWindow!.addSubview(view)
Add you view as the subview of NavigationController.
[self.navigationController.navigationBar addSubview: overlayView)]
You can also add it over the window:
UIView *view = /* Your custom view */;
UIWindow *window = [UIApplication sharedApplication].keyWindow;
[window addSubview:view];
Hope this helps.. :)
I'd use a UIViewController subclass containing a "Container View" that embeds your others view controllers. You'll then be able to add the navigation controller inside the Container View (using the embed relationship segue for example).
See Implementing a Container View Controller
Here is a simple elegant solution that is working for me. You can set the z position of the navigation bar to below the view:
self.navigationController.navigationBar.layer.zPosition = -1;
Just remember to set it back to 0 when done.