2017-04-03 75 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) 
}