I have UIViewController (for example, loginVC) and I’m trying to add it’s view on top of all views.
I tried to add this view to AppDelegate
[[AppDelegate sharedDelegate].window addSubview:loginVC.view];
But in this case autorotation doesn’t work, so I tried to add this view to NavigationController‘s view. NavigationController is rootViewController:
[[AppDelegate sharedDelegate].navigationController.view addSubview:loginVC.view];
It looks good and autorotating, but it has strange behavior when rotating.
After beginning of rotation, navigation bar is showing on top of loginVC.view and at the end of rotation is going behind this view, like it shown on screenshots (I’ve set red background to make it more visible, background is transparent, to see all stuff behind this view):



What I’ve tried:
-
I found this somewhere on stackoverflow: disable UIView animations before rotating and enable them after rotating – doesn’t look good, because rotating occurs without animation (it’s a bit obvious)
-
tried to make navigationBar hidden before rotation and make it visible after rotation, but in this case navigationBar bringing on top of loginVC.view
Next thing I gonna do – add this view on AppDelegate’s window and handle rotation manually, but maybe there is some better way to do this?
UPD:
screenshots:



You can see issue on second screenshot: navigation bar is on top
My friend helped me with this problem
Here is the solution:
In AppDelegate I’ve created
UIWindowproperty:Initialized it when application starts
And then, in loginVC:
UPD:
No need to use
makeKeyAndVisiblemethod of UIWindow, second window will be always on top of first one.UPD2:
Again updating my answer, maybe it will be useful for somebody.
Without
makeKeyAndVisibleI couldn’t useUITestFields so I uncommented that code and faced another problem:I have
UIViewController, create an instance of anotherUIViewControllerinside this controller and call[self presentViewController:...]. In presentedUIViewControllerI’m creatingloginVC, but when I call[[[AppDelegate sharedDelegate] window] makeKeyAndVisible];presented viewController disappears, but first view controller still has this controller as
presentedViewController, so I can’t present other view controllers.My solution was change
makeKeyAndVisibleonmakeKeyWindow.