繁体   English   中英

从UITabBarController以模态方式呈现ViewController而不隐藏选项卡栏

[英]Present ViewController modally from UITabBarController without hiding the tab bar

我有一个UITabBarController有5个项目。 我还有一个带有几个项目的侧边菜单。 当点击侧面菜单中的一个项目时,我需要以模态方式呈现视图控制器而不隐藏标签栏。 我尝试了以下方法:

  1. selectedViewController呈现它

      tabBarController.selectedViewController?.present(contactsViewController, animated: false, completion: {}) 
  2. UITabBarController本身呈现它

     tabBarController.present(contactsViewController, animated: true) {} 
  3. 将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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM