swift – 用动画交换rootViewController?
发布时间:2020-12-14 05:49:26 所属栏目:百科 来源:网络整理
导读:我试图用标签栏交换到另一个根视图控制器;通过应用程序委托,我想添加过渡动画。默认情况下,它只显示没有任何动画的视图。 let tabBar = self.instantiateViewController(storyBoard: "Main",viewControllerID: "MainTabbar")let appDelegate = UIApplicati
我试图用标签栏交换到另一个根视图控制器;通过应用程序委托,我想添加过渡动画。默认情况下,它只显示没有任何动画的视图。
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)并最终使用了这个:(但遗憾的是不记得为什么)
guard 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 }) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |