【问题标题】:Present ViewController in front of UITabBarController's tabBar and hide this tabBar在UITabBarController的tabBar前面呈现ViewController并隐藏这个tabBar
【发布时间】:2015-09-26 15:55:53
【问题描述】:

在我的项目中,我有一个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

    }

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

【问题讨论】:

  • 您的模态视图是否嵌入在导航控制器中?
  • 不,我的项目中没有任何导航控制器
  • @TheSD 我也在做同样的事情,并且模态视图嵌入在导航控制器中。你能指导我吗?

标签: ios swift uiviewcontroller uitabbarcontroller uitabbar


【解决方案1】:

您应该从标签栏控制器展示新的 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)

        })

    }

【讨论】:

  • 或者直接使用modalPresentationStyle = .overFullScreen
【解决方案2】:

在 Swift 5 中,

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-14
    • 1970-01-01
    • 2011-04-20
    • 2021-06-04
    • 2016-10-07
    • 1970-01-01
    • 2011-08-17
    • 1970-01-01
    相关资源
    最近更新 更多