Frage

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?

War es hilfreich?

Lösung 2

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

Andere Tipps

if(st.version == 7){

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

}else{

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

}

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.

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?

Override the -edgesForExtendedLayout method in your view controller

-(UIRectEdge)edgesForExtendedLayout {
    return UIRectEdgeNone;
}

If you want to hide status bar from a particular view add this method in that particular view.m file

- (BOOL)prefersStatusBarHidden
{
   return YES;
}

What about setting self.automaticallyAdjustsScrollViewInsets = NO; in viewDidLoad of your view controller or in IB?

  1. Try to set MapView(ScrollView) automaticallyAdjustsScrollViewInsets = NO;
  2. Try to set edgesForExtendedLayout to UIRectEdgeNone;
  3. Try to use UIViewController.topLayoutGuide, see the Q&A from apple about this issue:Preventing the Status Bar from Covering Your Views.
  4. Try to use the bar position delegation, see UIBarPositioningDelegate Protocol Reference

According to your description and screenshots, you are trying to move the whole UINavigationController.view.frame 20 pt, and the MapView(ScrollView) did something to prevent it happened (or re-set), put some breakpoint and log to track the frame of UINavigationController.view.frame changed.

Could you please provide a sample project? I'm so curious about what really happened.

try this

- (void)viewWillAppear:(BOOL)animated
{
   self.navigationController.navigationBar.translucent = NO;
}


- (void)viewDidAppear:(BOOL)animated
{
    self.navigationController.navigationBar.translucent = YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[application setStatusBarHidden:YES];
return YES;}

Please add this line to your code.This will hide the status bar from your app.

If you have a xib. Did you try to enabled Top Bar in simulated Metrics ?

enter image description here

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top