在 UITabBarController 的 tabBar 前面显示 ViewController 并隐藏这个 tabBar

Present ViewController in front of UITabBarController's tabBar and hide this tabBar

在我的项目中我有一个 UITabBarController。其中一个 ViewControllers 我有按钮。当我点击这个按钮时,一个新的 ViewController 以模态呈现。

问题是,当第二个 VC 出现时,tabBarControllertabBar 仍然可见。当我尝试使用此方法将其隐藏在第一个 ViewController 的操作 openFiltersList() 中时:

self.tabBarController?.tabBar.hidden = true

它隐藏了,但是当我试图取消隐藏它时,当我关闭第二个 VC 时,将此参数设置为 false 不起作用,tabBar 保持隐藏状态。 这是第一个和第二个的代码:

首先(InvitesViewController,tabBarController 的视图控制器之一):

func openFiltersList() {

        var filtersView : UIViewController = self.storyboard?.instantiateViewControllerWithIdentifier("filtersViewController") as! FiltersViewController
        filtersView.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext


        self.presentViewController(filtersView, animated: true) { () -> Void in

            UIView.animateWithDuration(0.3, animations: { () -> Void in

                filtersView.view.backgroundColor = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 0.5)

            })

        }

        self.tabBarController?.tabBar.hidden = true

    }

第二(FiltersViewController,未嵌入任何地方):

@IBAction func dismiss(sender: AnyObject) { // close button action

        self.dismissViewControllerAnimated(true, completion: nil)

        var destinationVC : UIViewController = self.storyboard?.instantiateViewControllerWithIdentifier("invitesViewController") as! InvitesViewController
        destinationVC.tabBarController?.tabBar.hidden = false

    }

我正在使用故事板作为界面。

您应该从标签栏控制器中展示新的 viewController:

 self.tabBarController?.presentViewController(filtersView, animated: true) { () -> Void in

        UIView.animateWithDuration(0.3, animations: { () -> Void in

            filtersView.view.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5)

        })

    }

在Swift5,

let popupController = ViewController()
popupController.modalPresentationStyle = .overFullScreen
self.present(popupController, animated: true, completion: nil)