我试图用标签栏交换到另一个根视图控制器;通过应用程序委托,我想添加过渡动画。默认情况下,它只显示没有任何动画的视图。
let tabBar = self.instantiateViewController(storyBoard: "Main",viewControllerID: "MainTabbar") let appDelegate = UIApplication.shared.delegate as! AppDelegate appDelegate.window = UIWindow(frame: UIScreen.main.bounds) appDelegate.window?.rootViewController = tabBar appDelegate.window?.makeKeyAndVisible()
这就是我交换到另一个rootview控制器的方式。
我前段时间评估过UIView.transition(来自:view,to:view)和UIView.transition(带有:view)并最终使用了这个:(但遗憾的是不记得为什么)
原文链接:https://www.f2er.com/swift/320247.htmlguard let window = UIApplication.shared.keyWindow else { return } guard let rootViewController = window.rootViewController else { return } let storyboard = UIStoryboard(name: "Main",bundle: nil) let vc = storyboard.instantiateViewController(withIdentifier: "MainTabbar") vc.view.frame = rootViewController.view.frame vc.view.layoutIfNeeded() UIView.transition(with: window,duration: 0.3,options: .transitionCrossDissolve,animations: { window.rootViewController = vc },completion: { completed in // maybe do something here })