我试图用标签栏交换到另一个根视图控制器;通过应用程序委托,我想添加过渡动画。默认情况下,它只显示没有任何动画的视图。
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 })
原文地址:https://www.jb51.cc/swift/320247.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。