![](/img/trans.png)
[英]UITabBarController add viewcontroller without tab bar item
[英]Present ViewController modally from UITabBarController without hiding the tab bar
我有一个UITabBarController
有5个项目。 我还有一个带有几个项目的侧边菜单。 当点击侧面菜单中的一个项目时,我需要以模态方式呈现视图控制器而不隐藏标签栏。 我尝试了以下方法:
从selectedViewController
呈现它
tabBarController.selectedViewController?.present(contactsViewController, animated: false, completion: {})
从UITabBarController
本身呈现它
tabBarController.present(contactsViewController, animated: true) {}
将Storyboard中的modal segue
从selectedViewController添加到contactsViewController并执行它
所有这些导致tabBar被隐藏。 是否可以在不隐藏标签栏的情况下以模态方式呈现视图控制器?
您可以使用UITabBarControllerDelegate
方法以模态方式显示菜单。
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool
{
if tabBarVC?.tabBar.selectedItem?.tag == 5
{
tabBarVC?.present(SideMenuManager.default.menuRightNavigationController!, animated: true, completion: nil)
return false
}
return true
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.