Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding MKMapView Causes Status Bar Issue in iOS 7

I'm solving the status bar issue in iOS 7 using

if(st.version == 7)
{
    CGRect screen = [[UIScreen mainScreen] bounds];
    CGRect frame = self.navigationController.view.frame;
    frame.origin.y = 20;
    frame.size.height = screen.size.height - 20;
    self.navigationController.view.frame = frame;
}

Since I'm using navigation controller and pushing from one to another using [self.navigationController pushViewController:newone animated:YES];. It works fine in all view controllers. But, if the viewcontroller has mkmapview in xib, status bar issue of ios 7 occurs.

If I delete the mapview form xib and push to that view controller means, it will be like,

enter image description here

If I add the mapview even by code below,

mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 100, 320, 100)];
[self.view addSubview:self.mapView];

It looks like,

enter image description here

How to solve this?

like image 589
Nazik Avatar asked Feb 06 '14 12:02

Nazik


4 Answers

if(st.version == 7){

   mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 120, 320, 100)];

}else{

   mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 100, 320, 100)];

}
like image 124
Chirag S Avatar answered Oct 30 '22 14:10

Chirag S


If you add mapView in viewWillAppear replace it in viewDidAppear.
Maybe you have this issue because you're doing manipulations with view's frames before your view is completely set up

like image 29
Roma Avatar answered Oct 30 '22 14:10

Roma


I would highly suggest against doing it like that.

If you're using interface builder, then add constraints based on how you want your application to look and the frame will auto adjust itself.

If you're not using interface builder, then still use constraints, but get a good tutorial about making constraints programatically (as I don't know how to do it myself).

Edit: The reason I HIGHLY suggest not doing it with hardcoded numbers is that it'll be a pain to do iOS 6/7 Landscape/Portrait 3.5/4 inch screens. That's 8 cases.

like image 21
Lord Zsolt Avatar answered Oct 30 '22 15:10

Lord Zsolt


i think you have some adjust your navigation Y position set -20px. that way it goes overlay. use this code your ViewController

CGRect screen = [[UIScreen mainScreen] bounds];
CGRect frame = self.navigationController.view.frame;
frame.origin.y =0;
frame.size.height = screen.size.height;
self.navigationController.view.frame = frame;

or may it you have use wantFullScreenLayout some where in your project

setWantsFullScreenLayout = YES:

statusbar section is located to the (0,0) point to catch. Statusbar and as large as the size of the current view to increase the value of mainScreen change the size of the bounds. Statusbar change the style of the translucent style.

this below link you get some clear idea about your issue

How do I get the navigation bar in a UINavigationController to update its position when the status bar is hidden?

like image 27
codercat Avatar answered Oct 30 '22 16:10

codercat