Status bar and navigation bar issue in IOS7

前端 未结 11 1791
眼角桃花
眼角桃花 2020-11-22 10:10

I am migrating my application to iOS 7. For handing the status bar issue I have added this code

if([[[UIDevice currentDevice] systemVersion] floatValue] >         


        
相关标签:
11条回答
  • 2020-11-22 10:22
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
        // Override point for customization after application launch.
        self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
    
        self.window.rootViewController = self.viewController;
    
     if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
    
            [application setStatusBarStyle:UIStatusBarStyleLightContent];
             [application setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
    
            self.window.clipsToBounds =YES;            
            self.window.frame =CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
        }
    
    
       [self.window makeKeyAndVisible];
        return YES;
    }
    

    set the following to info.plist

    View controller-based status bar appearance = NO;

    0 讨论(0)
  • 2020-11-22 10:24

    i solved this by using below code

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
     {
        if(landScape mode)
    
           if ([UIDevice currentDevice].systemVersion.floatValue>=7) {
            CGRect frame = self.window.frame;
           frame.size.width -= 20.0f;
          frame.origin.x+= 20.0f;
           self.window.frame = frame;
        }
    
    
     if(portrait)
    
        if ([[[UIDevice currentDevice]systemVersion]floatValue] >= 7.0) {
        [application setStatusBarStyle:UIStatusBarStyleLightContent];
    
        CGRect frame = self.window.frame;
        frame.origin.y += 20.0f;
        frame.size.height -= 20.0f;
        self.window.frame = frame;
    }
    return YES;
    
     }
    
    0 讨论(0)
  • 2020-11-22 10:25

    MUCH MUCH MUCH simpler answer:

    Align the top of your view to the "top layout guide", but control-dragging "Top Layout Guide" to your view and setting the "vertical" constraint. See this answer for a picture reference.

    The way it works is - the "Top Layout Guide" will automagically ajust itself for when the status bar is or is not there, and it will all work - no coding required!

    P.S. In this particular example, the background showing through at the bottom should also be resolved by setting an appropriate vertical constraint of the view's bottom, to it's superview, or whatever...

    0 讨论(0)
  • 2020-11-22 10:36

    I am late for this Answer, but i just want to share what i did, which is basically
    the easiest solution

    First of all-> Go to your info.plist File and add Status Bar Style->Transparent Black Style(Alpha of 0.5)

    Now ,here it Goes:-

    Add this code in your AppDelegate.m

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
        {
         //Whatever your code goes here
      if(kDeviceiPad){
    
         //adding status bar for IOS7 ipad
             if (IS_IOS7) {
                  UIView *addStatusBar = [[UIView alloc] init];
                  addStatusBar.frame = CGRectMake(0, 0, 1024, 20);
                  addStatusBar.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; //change this to match your navigation bar
                  [self.window.rootViewController.view addSubview:addStatusBar];
                        }
                    }
        else{
    
             //adding status bar for IOS7 iphone
            if (IS_IOS7) {
                UIView *addStatusBar = [[UIView alloc] init];
                addStatusBar.frame = CGRectMake(0, 0, 320, 20);
                addStatusBar.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; //You can give your own color pattern
                [self.window.rootViewController.view addSubview:addStatusBar];
            }
    
        return YES;
       }
    
    0 讨论(0)
  • 2020-11-22 10:38

    Fix for status bar issue in IOS 7

    Finally I fixed the status bar over lap issue using the delta value property in xcode5. First I have increased origin - y 20pxl to all the controller used in the Xib (it seams to be working fine only in IOS 7), after that I set the delta value for all the view controller origin -y to -20 it works fine in both iOS 6 and iOS 7.

    Steps to do that.

    Xcode 5 provide preview option to view the appearance of the xib in different view based on the OS version.

    Choose preview option from assistant editor

    Click assistant editor

    enter image description here

    and choose preview option to preview selected view controller in different version.

    enter image description here

    view controller view preview option.

    enter image description here

    in preview you can find the toggle option to preview view in different version. In preview u can feel the status bar issue clearly if its not fixed properly by toggle the version.

    Three steps to fix the status bar issue: step 1: Make sure the view target us 7.0 and later in File inspector.

    enter image description here

    Step 2 : Increase the origin - y with 20 pixel (exactly the size of the status bar) for all the controls added in the view controller.

    Step 3 : Set the delta value of origin y to -20 for all the controls then only it will adjust automatically based on the version. Use preview now and feel the differ that the controls automatically adjust because of the delta value.

    enter image description here

    Once the status bar issue fixed, issue while presenting the model view (ZbarSDk controller) is also fixed automatically.

    Preview screen :

    enter image description here

    0 讨论(0)
提交回复
热议问题