Reputation: 14320
I have an app with an animated splashscreen and a main interface.
To transition from the splashscreen to the main interface I used this code:
presentViewController(mainViewController, true) {
UIApplication.sharedApplication.keyWindow.rootViewController = mainViewController
}
But apparently this method ruins autorotation (took me a while to find that one). Now I have the issue that this autorotation is not with animation.
I guess this is not with animation because the old viewcontroller still lives below the other viewcontroller and it just forwards the new orientation.
How can I properly transition from one viewcontroller to the next while being able to destroy the old viewcontroller and keep rotation?
Edit: I noticed that my homescreen rotates when I close my app (from its startup orientation to the orientation the app was in when I closed it)
Upvotes: 0
Views: 174
Reputation: 14320
In addition to what Kemal said, I have found my specific issue:
I don't really understand why this gives that problem. I have a storyboard that is set in the Info.plist
as the main interface (I ignored this, because I don't need it). In my AppDelegate.finishedLaunching
I create a new window and set its root view controller, which I then set as key window. Removing either the window setting in AppDelegate
or Info.plist
resolves the issue.
Upvotes: 2
Reputation: 1660
According to UIWindow documentation;
If the window has an existing view hierarchy, the old views are removed before the new ones are installed.
Source Link -> here
So, system automatically destroy while decide to no longer need your first RootViewController. You can handle transition like this;
if var topRootController = UIApplication.sharedApplication().keyWindow?.rootViewController {
while (topRootController.presentedViewController != nil) {
topRootController = topRootController.presentedViewController!
}
topRootController.presentViewController(homeController, animated: true, completion: nil)
}
Upvotes: 1