Status bar and navigation bar issue in IOS7

2018-12-31 10:12发布

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

if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f)
{
    CGRect frame = self.navigationController.view.frame;
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        frame.origin.y = 20;
    }
    else
    {
        frame.origin.x = 20;
    }
    [self.navigationController.view setFrame:frame];
}

This is working fine in normal case. If I am changing orientation (app supports only landscape orientation) or presenting any view controller and dismissing model view controller my view controller alignment changed. The status bar again overlaps my view controller. This piece of code is not working at all. Please guide me to fix this status bar issue.

Case 2: This is how I am presenting my view controller

ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    reader.supportedOrientationsMask = ZBarOrientationMaskLandscape;
else
    reader.supportedOrientationsMask = ZBarOrientationMaskPortrait;

    [self presentModalViewController:reader animated:YES];

Ref:

enter image description here

Thanks in advance.

11条回答
笑指拈花
2楼-- · 2018-12-31 10:46

just set the following code in viewWillAppear.

 if ([[[UIDevice currentDevice] systemVersion] floatValue]<= 7) {
    self.edgesForExtendedLayout = UIRectEdgeNone;
 }
查看更多
栀子花@的思念
3楼-- · 2018-12-31 10:47

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;

 }
查看更多
裙下三千臣
4楼-- · 2018-12-31 10:48
#define _kisiOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)

 if (_kisiOS7)
    {
        [[UINavigationBar appearance] setBarTintColor:_kColorFromHEX(@"#011C47")];
    }
    else
    {
        [[UINavigationBar appearance] setBackgroundColor:_kColorFromHEX(@"#011C47")];
        [[UINavigationBar appearance] setTintColor:_kColorFromHEX(@"#011C47")];
    }
查看更多
只靠听说
5楼-- · 2018-12-31 10:53

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

查看更多
冷夜・残月
6楼-- · 2018-12-31 10:55

With Salesforce SDK 2.1 (Cordova 2.3.0) we had to do the following to get the status bar appear on the initial load of the App and coming back from the background (iPhone and iPad):

Contrarily to other solutions posted here, this one seems to survive rotation of the device.

1-Create a category of theSFHybridViewController

#import "SFHybridViewController+Amalto.h"

@implementation SFHybridViewController (Amalto)

- (void)viewWillAppear:(BOOL)animated
    {
        //Lower screen 20px on ios 7
        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
            CGRect viewBounds = self.view.bounds;
            viewBounds.origin.y = 20;
            viewBounds.size.height = viewBounds.size.height - 20;
            self.webView.frame = viewBounds;
        }

    [super viewWillAppear:animated];
    }

    - (void)viewDidLoad
    {

        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
            CGRect viewBounds = self.view.bounds;
            viewBounds.origin.y = 20;
            viewBounds.size.height = viewBounds.size.height - 20;
            self.webView.frame = viewBounds;
        }
        [super viewDidLoad];
    }

@end

2-Add to AppDelegate.m imports

#import "SFHybridViewController+Amalto.h"

3-Inject at the end of of method didFinishLaunchingWithOptions of AppDelegate

//Make the status bar appear
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {

    [application setStatusBarStyle:UIStatusBarStyleLightContent];
    [application setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
}

4-Add to App-Info.plist the property

View controller-based status bar appearance with value NO

查看更多
登录 后发表回答