我有一个项目,其中包含一个选项卡控制器,作为主‘页面’。
我想添加一个UITabBar按钮项,它以模态的方式呈现一个视图控制器,并在该视图控制器中添加一个取消该视图控制器并返回到上一个选项卡选择的取消按钮。
要澄清的是,这是iOS的Medium应用程序使用的东西,当你点击create帖子项目时,它会以模态的方式显示它,并在你想要的时候关闭它。
我可以呈现视图控制器,但我不能忽略它。
希望我把话说明白了。
示例:

发布于 2017-02-27 09:28:17
所以我已经成功地解决了这个问题,希望这个答案能在未来对某些人有所帮助。
首先,在我加载的第一个视图控制器上,假设我的'Home‘视图控制器将tabBarController委托设置为我的AppDelegate.swift文件(这是我的个人偏好),如下所示:
self.tabBarController?.delegate = UIApplication.shared.delegate as? UITabBarControllerDelegate然后,在我的AppDelegate.swift文件中,我将委托UITabBarControllerDelegate添加到类属性中,以便可以访问tabBarController委托函数,例如
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {}
然后编辑该函数以与我的特定视图控制器交互。
函数的最终版本:
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
if viewController is ViewControllerToPresentModaly {
if let newVC = tabBarController.storyboard?.instantiateViewController(withIdentifier: "modalVC") {
tabBarController.present(newVC, animated: true)
return false
}
}
return true
}如果您想要常规的选项卡行为,可以选择return true或您自己的return false
;)
https://stackoverflow.com/questions/42476170
复制相似问题