Status bar and navigation bar issue in IOS7

前端 未结 11 1790
眼角桃花
眼角桃花 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:13
    #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")];
        }
    
    0 讨论(0)
  • 2020-11-22 10:14

    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

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

    To hide status bar in ios7 follow these simple steps :

    In Xcode goto "Resources" folder and open "(app name)-Info.plist file".

    • check for "View controller based status bar appearance" key and set its value "NO"
    • check for "Status bar is initially hidden" key and set its value "YES"

    If the keys are not there then you can add it by selecting "information property list" at top and click + icon

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

    Hear we can do this for all views at once

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
    {
    // Notification for the orientaiton change
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(applicationDidChangeStatusBarOrientation:)
                                                 name:UIApplicationDidChangeStatusBarOrientationNotification
                                               object:nil];
    
    // Window framing changes condition for iOS7 or greater
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        statusBarBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, -20, self.window.frame.size.width, 20)];//statusBarBackgroundView is normal uiview
        statusBarBackgroundView.backgroundColor = [UIColor colorWithWhite:0.000 alpha:0.730];
        [self.window addSubview:statusBarBackgroundView];
        self.window.bounds = CGRectMake(0, -20, self.window.frame.size.width, self.window.frame.size.height);
    }
    // Window framing changes condition for iOS7 or greater
    
    self.window.rootViewController = navigationController;
    [self.window makeKeyAndVisible];
    
    
    return YES;
    }
    

    And While we are using orientation we can add below method in app delegate to set it via orientation.

    - (void)applicationDidChangeStatusBarOrientation:(NSNotification *)notification
    {
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        statusBarBackgroundView.hidden = YES;
        UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
        int width = [[UIScreen mainScreen] bounds].size.width;
        int height = [[UIScreen mainScreen] bounds].size.height;
    
        switch (orientation) {
            case UIInterfaceOrientationLandscapeLeft:
                self.window.bounds =  CGRectMake(-20,0,width,height);
                statusBarBackgroundView.frame = CGRectMake(-20, 0, 20, height);
                break;
            case UIInterfaceOrientationLandscapeRight:
                self.window.bounds =  CGRectMake(20,0,width,height);
                statusBarBackgroundView.frame = CGRectMake(320, 0, 20, height);
                break;
            case UIInterfaceOrientationPortraitUpsideDown:
                statusBarBackgroundView.frame = CGRectMake(0, 568, width, 20);
                self.window.bounds =  CGRectMake(0, 20, width, height);
                break;
            default:
                statusBarBackgroundView.frame = CGRectMake(0, -20, width, 20);
                self.window.bounds =  CGRectMake(0, -20, width, height);
                break;
        }
        statusBarBackgroundView.hidden = NO;
    }
    }
    

    You should Add below navigation controller category for it

    .h

    #import <UIKit/UIKit.h>
    #import <QuartzCore/QuartzCore.h>
    @interface UINavigationController (iOS6fix)
    
    @end
    

    .m

    #import "UINavigationController+iOS6fix.h"
    @implementation UINavigationController (iOS6fix)  
    
    -(BOOL)shouldAutorotate
    {
          return [[self.viewControllers lastObject] shouldAutorotate];
    }
    
    -(NSUInteger)supportedInterfaceOrientations
    {
          return [[self.viewControllers lastObject] supportedInterfaceOrientations];
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
         return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
    }
    
    @end
    
    0 讨论(0)
  • 2020-11-22 10:21

    There are several different ways. One approach is to use .plist file

    • Add a new key "View controller-based status bar appearance" and set value as "NO".
    • Add another key "Status bar is initially hidden" and set value as "YES".

    This will hide status bar throughout project.

    Screenshot for approach

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

    just set the following code in viewWillAppear.

     if ([[[UIDevice currentDevice] systemVersion] floatValue]<= 7) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
     }
    
    0 讨论(0)
提交回复
热议问题