为什么我的应用程序在没有动画的情况下旋转?

Why does my app rotate without animation?

我有一个带有动画闪屏和主界面的应用程序。

为了从闪屏过渡到主界面,我使用了以下代码:

presentViewController(mainViewController, true) {
    UIApplication.sharedApplication.keyWindow.rootViewController = mainViewController
}

但显然这种方法破坏了自转(我花了一段时间才找到那个)。现在我有一个问题,这个自转不是动画。

我想这与动画无关,因为旧的 viewcontroller 仍然位于另一个 viewcontroller 的下方,它只是转发新的方向。

我如何正确从一个viewcontroller过渡到另一个viewcontroller,同时能够破坏旧的viewcontroller并保持轮换?

编辑:我注意到我的主屏幕在我关闭我的应用程序时旋转(从它的启动方向到我关闭它时应用程序所在的方向)

根据 UIWindow 文档;

If the window has an existing view hierarchy, the old views are removed before the new ones are installed.

来源Link -> here

因此,系统在决定不再需要您的第一个 RootViewController 时自动销毁。您可以像这样处理过渡;

if var topRootController = UIApplication.sharedApplication().keyWindow?.rootViewController {
    while (topRootController.presentedViewController != nil) {
        topRootController = topRootController.presentedViewController!
    }
    topRootController.presentViewController(homeController, animated: true, completion: nil)
}

除了凯末尔所说的,我还发现了我的具体问题:

我真的不明白为什么会出现这个问题。我有一个在 Info.plist 中设置为主界面的故事板(我忽略了这个,因为我不需要它)。在我的 AppDelegate.finishedLaunching 中,我创建了一个新的 window 并设置了它的根视图控制器,然后我将其设置为键 window。删除 AppDelegateInfo.plist 中的 window 设置可解决问题。