Modal view controller hides the tab bar

In a tab based application, by clicking one of the tabs, I want to display a modal view controller with some information. In my delegate's didSelectViewController method, I add a modal view. But it takes up the whole screen and hides the tab bar. I don't want to hide the tab bar, I just want to display a modal view that appears and can be dismissed.

How should I do it?

Please, help.

Thanks in advance.

+3


source to share


5 answers


For example, if secondViewController is the second viewController for your second pane, you would do like this:



[secondViewController.view addSubview:theViewYouWantToShow];

+2


source


Modular View Controllers are always displayed in full screen mode on iPhone. If you do not want to hide the tab bar, you need to present this view in some other way than modal.



+4


source


I was able to "present" a new view controller, above another, below the tab bar by setting modalPresentationStyle

to .currentContext

.

let newViewController = UIViewController()
newViewController.view.backgroundColor = UIColor.red
newViewController.modalPresentationStyle = .currentContext
newViewController.modalTransitionStyle = UIModalTransitionStyle.flipHorizontal
present(newViewController, animated: true, completion: nil)

      

Edit: Due to more tests, the above may have incorrect behavior if someone changes the WHILE tab when presented newViewController

.

To "fix", I created a "switch" - a UIViewController

that animates between view controllers I want to flip under the tab bar:

view.addSubview(nextView)
            UIView.transition(from: currentView,
                              to: nextView,
                              duration: 0.5,
                              options: animation,
                              completion: { (_) in
                currentView.removeFromSuperview()
            })

      

In this case currentView

, this is the ViewControllerOne view (currently visible) and the nextView

ViewControllerTwo view (the one we want to present).

+2


source


On iOS, the Modal View controller always has the highest priority in all available controllers. Thus, you cannot use Modal View Controller in your case.

If you just want to display the popup on the screen with backsurface visibility, just use UIAlertView . You can add "OK" or "CANCEL" button according to your requirement to remove the warning.

or

If you want to show the full view with tab bar visibility, add the view in that tab as a subtitle. You can give it a popup feel using the transform property of the view.

+1


source


You can present it modally by setting PresentationStyle. This style presents the viewController squared and does not fill the entire screen.

self.modalPresentationStyle = UIModalPresentationFormSheet;

      

You can also set the transition:

self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

      

+1


source







All Articles