我已经创建了一个选项卡式应用程序,并能够使用下面的代码以模态形式显示视图,但是,我一直坚持关闭视图并显示选项卡栏和第一个视图控制器。
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let signUpViewController = storyboard.instantiateViewController(withIdentifier:"SignUpViewController") as! SignUpViewController
self.window?.makeKeyAndVisible()
self.window?.rootViewController = signUpViewController
答案 0 :(得分:0)
在signUpViewController
内,在为tabBarController提供IB中的情节提要标识符后执行此操作
let tab = storyboard!.instantiateViewController(withIdentifier:"tab")
UIApplication.shared.keyWindow?.rootViewController = tab
OR
(UIApplication.shared.delegate as! AppDelegate).window?.rootViewController = tab
答案 1 :(得分:0)
您应在标签栏vc上方显示模态vc
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let signUpViewController = storyboard.instantiateViewController(withIdentifier:"SignUpViewController") as! SignUpViewController
signUpViewController.modalPresentationStyle = UIModalPresentationStyle.fullScreen
signUpViewController.modalTransitionStyle = UIModalTransitionStyle.coverVertical
self.window.rootViewController.present(myModalViewController, animated: true, completion: nil)
(如果self.window.rootViewController-您的标签栏视图控制器)
在这种情况下,您可以在模态vc中使用 dismiss(动画:true,完成:nil) 方法将其关闭。
答案 2 :(得分:0)
在您的TabBarViewController
中,在显示SignUpViewController
时执行以下操作
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier:"SignUpViewController")
viewController.modalPresentationStyle = .overFullScreen
self.presentViewController(viewController, animated:true)
并且在关闭时,只需从SignUpViewController
例如dismissViewControllerAnimated