2017-04-03 55 views
0

我在Appdelegate的didFinishLaunchingWithOptions方法中有一些代码,根据代码显示不同的ViewController。添加此代码后动画不显示方向将改变。但如果我删除此代码,然后动画shows.can有人解释我如何解决这个问题?这是代码。Orienatation动画不显示何时方向会改变ios Swift

 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() 
+0

你可以告诉我你是如何改变之前设置RootViewController的和你不使用任何NavigationController的设置RootViewController的中你的项目。 – Aashish1aug

回答

1

添加以下代码在您的视图控制器,并给予尝试

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) 
}