Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to present a modal view on top of tab bar controller?

Tags:

ios

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

like image 914
Pakpoom Thaweesitthichat Avatar asked Jan 11 '17 15:01

Pakpoom Thaweesitthichat


2 Answers

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)
like image 65
Samantha Avatar answered Nov 16 '22 04:11

Samantha


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

like image 29
Gabriel Cartier Avatar answered Nov 16 '22 05:11

Gabriel Cartier