Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS MapView goes under navigation bar, status bar, and tab bar controller

I have a ViewController with a navigation controller and a tab bar controller. This ViewController has 2 buttons that toggle the visibility of a scroll view and a map view. The main thing is to have these 2 buttons always show up in the same place regardless of orientation or the view that happens to be visible.

The problem I am having is that the MapView won't size properly. If I just give it a frame from self.view.bounds it goes under the navigation bar / tab bar - basically taking up the whole screen. This throws off the location of my toggle buttons.

I noticed my ScrollView does the same (using a background color and a translucent navigation bar) but the positioning of sub views on it stay within the visible area (between the navigation bar and the tab bar). So when I add my toggle buttons, they show in the correct place.

When I press the toggle buttons, I just re-assign the parent view of the buttons to the now displayed view (ScrollView or MapView). This always works on the scroll view but due to the positioning, they end up going under the navigation bar when the MapView is displayed.

I have tried creating the frame for the MapView manually but I get odd results. I use this for the frame:

CGRect mapFrame = CGRectMake(
    0,
    (self.navigationController.navigationBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height),
    self.view.frame.size.width,
    (
     self.view.frame.size.height
     - (self.navigationController.navigationBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height + self.tabBarController.tabBar.frame.size.height)
    )
);

I then set the auto resizing masks

[self.mapView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];

But with this, if I enter into the view controller in landscape mode - the MapView is off the screen. If I enter in portrait mode and then rotate to landscape, the top margin is off but about 10 points so it still goes under the navigation bar a bit (and has a visible margin between the tab bar and the bottom of the map view).

How can I make the MapView subviews only display within the visible region like the ScrollView does? I don't mind so much if the map itself goes under the navigation bar / tab bar

like image 276
shiznatix Avatar asked Oct 03 '13 12:10

shiznatix


People also ask

What is a navigation bar in an app?

A navigation bar appears at the top of an app screen, enabling navigation through a hierarchy of content. A navigation bar also provides a natural place to display a screen’s title — helping people orient themselves in your app or game — and it can include controls that affect the screen’s content.

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 does the tab bar controller work in Android?

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. Figure 2-1 shows the tab bar interface implemented by the Clock app. The tab bar controller has its own container view, which encompasses all of the other views, including the tab bar view.

What is the manager for a tab bar interface?

The manager for a tab bar interface is a tab bar controller object. The tab bar controller creates and manages the tab bar view and also manages the view controllers that provide the content view for each mode. Each content view controller is designated as the view controller for one of the tabs in the tab bar view.


1 Answers

Ugh, I found the answer just a few minutes ago. I have no idea why this is the default behavior on iOS 7 but alas, there it is.

The solution is to add this to the viewDidLoad on the ViewController

[self setEdgesForExtendedLayout:UIRectEdgeNone];
[self setAutomaticallyAdjustsScrollViewInsets:NO];

Much thanks to the post here

like image 199
shiznatix Avatar answered Oct 17 '22 01:10

shiznatix