Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modal view controller hides tab bar

In my tab based app, on clicking one of the tabs, I want to display a modal view controller with some info. In my app delegate's didSelectViewController method, I am adding modal view. But it occupies entire screen and hides the tab bar. I don't want to hide the tab-bar, just want to display modal-view which pops up and can be dismissed.

How do I do it?

Please help.

Thanks in advance.

like image 424
iOSDev Avatar asked Jan 24 '13 04:01

iOSDev


People also ask

How do you hide the tab bar when a view controller is shown?

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.

How do I get rid of the tab bar in Swift?

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

How do I hide the tabBar in Objective C?

In case you're using tabbar with navigation controller hidesBottomBarWhenPushed will not work, but tabBarController. tabBar. hidden will do.

How do I hide the bottom bar in Swift?

Answer: Use self. tabBarController?. tabBar. hidden instead of hidesBottomBarWhenPushed in each view controller to manage whether the view controller should show a tab bar or not.

How do you use a tab bar controller?

Each content view controller is designated as the view controller for one of the tabs in the tab bar view. When a tab is tapped by the user, the tab bar controller object selects the tab and displays the view associated with the corresponding content view controller.

Can a tab bar view be modified?

When a tab bar view is part of a tab bar interface, it must not be modified. In a tab bar interface, the tab bar view is considered to be part of a private view hierarchy that is owned by the tab bar controller object.

What is the difference between view controller and tab bar view?

The tab bar controller has its own container view, which encompasses all of the other views, including the tab bar view. The custom content is provided by the view controller of the selected tab. When a tab bar view is part of a tab bar interface, it must not be modified.

How to modify the list of active tabs in a Tabbar?

When a tab bar view is part of a tab bar interface, it must not be modified. In a tab bar interface, the tab bar view is considered to be part of a private view hierarchy that is owned by the tab bar controller object. If you do need to change the list of active tabs, you must always do so using the methods of the tab bar controller itself.


2 Answers

Modal view controllers are always presented full screen on an iPhone. If you don't want to hide the tab bar, then you need to present this view in some other way besides modal.

like image 83
rdelmar Avatar answered Oct 04 '22 17:10

rdelmar


I was able to "present" a new view controller, over another, UNDER 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: From more testing, the above can have some buggy behavior if someone changes the tab WHILE the newViewController is presented.

To "fix," I created a "switcher" - a UIViewController that animates between the view controllers that 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 is the view of ViewControllerOne (the currently visible one), and the nextView is view of ViewControllerTwo (the one we want to present).

like image 38
kgaidis Avatar answered Oct 04 '22 17:10

kgaidis