【问题标题】:Present and dismiss view modally in tabbed application using swift使用 swift 在选项卡式应用程序中模态显示和关闭视图
【发布时间】:2018-09-25 14:49:14
【问题描述】:

我已经创建了一个选项卡式应用程序,并且能够使用下面的代码以模态方式呈现一个视图,但是,我坚持关闭视图并显示选项卡栏和第一个视图控制器。

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let signUpViewController = storyboard.instantiateViewController(withIdentifier:"SignUpViewController") as! SignUpViewController
self.window?.makeKeyAndVisible()
self.window?.rootViewController = signUpViewController

【问题讨论】:

  • 您没有在代码中以模态方式呈现任何内容。你用你的signUpViewController替换你的应用程序中的rootViewController(我猜是标签栏控制器)。

标签: ios swift appdelegate modalviewcontroller presentmodalviewcontroller


【解决方案1】:

signUpViewController 内部,在 IB 中为 tabBarController 提供故事板标识符后执行此操作

let tab = storyboard!.instantiateViewController(withIdentifier:"tab") 
UIApplication.shared.keyWindow?.rootViewController = tab

(UIApplication.shared.delegate as! AppDelegate).window?.rootViewController = tab

【讨论】:

    【解决方案2】:

    您应该在标签栏 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(animated: true, completion: nil) 方法将其关闭。

    【讨论】:

      【解决方案3】:

      在您的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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-18
        • 1970-01-01
        • 2012-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多