'How can I present a modal view on top of a tab bar controller?

I made one button on the navigation bar. I made it to modal view. But the problem is I can't bring this modal view on the top of the tab bar. What should I do?

In addition, I have used storyboard's segue to present the modal view.

Enter to see storyboard image

Enter to see simulator image

ios


Solution 1:[1]

It's hard to tell from the screenshots, but it seems like what you want is for the tab bar to become greyed out just like the background of the view inside the UITabBarController?

Where are you presenting the modal view from? If view controller A is inside your tab bar controller, then presenting the modal view from A will result in the tab bar not getting grayed out. If you present from the tab bar controller, it should do what you want.

In the presenting view controller's code, instead of

present(modalViewController, animated: true, completion: completion)

try using

tabBarController?.present(modalViewController, animated: true, completion: completion)

(Where modalViewController and completion are whatever you mean to use for these arguments, of course.)

If you are using a segue to present the modal controller, then the same concept applies. Move the segue to the tab bar controller and then perform it on the tab bar controller from the presenting view controller.

tabBarController?.performSegue(withIdentifier: "yourSegueIdentifier", sender: tabBarController)

Solution 2:[2]

You can simply use the modalPresentationStyle of your view controller and set it to fullScreen or overFullScreen and this will automatically hide the tab bar, whether the view controller is presented from the tab bar or not.

Swift 4 example:

presentedVC.modalPresentationStyle = .overFullScreen

You can check the documentation for more information: UIModalPresentationStyle

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter Mortensen
Solution 2 Peter Mortensen