Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In my project I have a UITabBarController. And on one of it's ViewControllers I have button. When I click this button, a new ViewController is presenting modally.

The problem is, when the second VC is presenting, tabBarController's tabBar is still visible. When I try to hide it in first ViewController's action openFiltersList() with this method:

self.tabBarController?.tabBar.hidden = true

it hides, but when I'm trying to unhide it, when I dismiss second VC, setting this parameter to falsedoesn't work, tabBar stays hidden. Here's the code for first and second:

First (InvitesViewController, one of the tabBarController's View Controllers):

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

    }

Second (FiltersViewController, not embedded anywhere):

@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

    }

I'm using storyboard for interface.

like image 722
vanelizarov Avatar asked Jul 08 '15 15:07

vanelizarov


People also ask

How do I hide a Tabbar in Swift?

Simply, Go to ViewController (in StoryBoard) -> Attribute inspector -> Under 'View Controller' section select 'Hide Bottom Bar on Push' checkbox.

How do I add a ViewController to the tab bar controller in StoryBoard?

To add the new View Controller to the Tab Bar Controller, right-click the Tab Bar Controller and drag it to the new View Controller. Select Relationship Segue. Now, the Tab Bar Controller has the third item and Relationship “view controllers” to “View Controller”.

How do I hide the bottom Tabbar in Swift?

If you don't want that behavior, you should set hidesBottomBarWhenPushed to true where applicable. This will hide the tab bar along with any toolbars you had showing, but only when a view controller is pushed onto the navigation stack. This allows you to show the tab bar at first, then hide it when you need more room.

What is the use of tab bar controller in Xcode?

The tab bar interface displays tabs at the bottom of the window for selecting between the different modes and for displaying the views for that mode. This class is generally used as-is, but may also be subclassed. Each tab of a tab bar controller interface is associated with a custom view controller.


2 Answers

In Swift 5,

let popupController = ViewController()
popupController.modalPresentationStyle = .overFullScreen
self.present(popupController, animated: true, completion: nil)
like image 42
nitin.agam Avatar answered Oct 10 '22 06:10

nitin.agam


You should present the new viewController from tab bar controller:

 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)

        })

    }
like image 131
DigitalBrain_DEV Avatar answered Oct 10 '22 08:10

DigitalBrain_DEV