20

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.

vanelizarov
  • 1,064
  • 1
  • 8
  • 24

2 Answers2

39

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)

        })

    }
ocodo
  • 29,401
  • 18
  • 105
  • 117
DigitalBrain_DEV
  • 1,093
  • 13
  • 27
10

In Swift 5,

let popupController = ViewController()
popupController.modalPresentationStyle = .overFullScreen
self.present(popupController, animated: true, completion: nil)
nitin.agam
  • 1,949
  • 1
  • 17
  • 24
  • set popupController.modalPresentationStyle = .fullScreen If you want to call viewwillappear when user come back to main screen. – Sourabh Sharma Jul 26 '22 at 13:38