簡體   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