Orienatation 动画未显示方向何时会更改 ios Swift



我在Appdelegate的didFinishLaunchingWithOptions方法中有一些代码,这些代码根据代码显示不同的ViewController。 添加此代码后,动画未显示方向何时会更改。但是如果我删除此代码,则动画显示.有人可以解释我如何解决此问题吗?这就是代码。

       self.window = UIWindow(frame: UIScreen.main.bounds)
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    var vc:UIViewController
    if (UserDefaults.standard.object(forKey: "Person") as? Bool) == nil {
        vc = storyboard.instantiateViewController(withIdentifier: "FirstNavigationView")
    }else{
        vc = storyboard.instantiateViewController(withIdentifier: "MainView")
    }
    self.window?.rootViewController = vc
    self.window?.makeKeyAndVisible()

在视图控制器中添加以下代码并尝试

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    coordinator.animate(alongsideTransition: nil, completion: {
        _ in
        UIView.setAnimationsEnabled(true)
    })
    UIView.setAnimationsEnabled(true)
    super.viewWillTransition(to: size, with: coordinator)
}

最新更新