IOS7 狀態欄和 Navigation Bar重疊的問題解決


 

 

一 Status bar重疊問題:

 

方法一:隱藏Status bar   在plist里面增加2個變量  Status bar is initially hidden  -> YES   View controller-based status bar appearance -> NO

方法二:改為和IOS6 一樣的顯示方式  

  1. Set UIViewControllerBasedStatusBarAppearance to NO in info.plist (To opt out of having view controllers adjust the status bar style so that we can set the status bar style by using the UIApplicationstatusBarStyle method.)

  2. In AppDelegate's application:didFinishLaunchingWithOptions, call

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        [application setStatusBarStyle:UIStatusBarStyleLightContent];
        self.window.clipsToBounds =YES;
        self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
    
        //Added on 19th Sep 2013
        self.window.bounds = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height);
    }

    方法三:

 

Set UIViewControllerBasedStatusBarAppearance to NO in info.plist

Pase this code in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
            [application setStatusBarStyle:UIStatusBarStyleLightContent];
            self.window.clipsToBounds =YES;
            self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height);

            //Added on 19th Sep 2013
            NSLog(@"%f",self.window.frame.size.height);
            self.window.bounds = CGRectMake(0,0, self.window.frame.size.width, self.window.frame.size.height);
        }

It may push down all your views by 20 pixels.To over come that use following code in -(void)viewDidAppear:(BOOL)animated method

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        CGRect frame=self.view.frame;
        if (frame.size.height==[[NSUserDefaults standardUserDefaults] floatForKey:@"windowHeight"])
        {
            frame.size.height-=20;
        }
        self.view.frame=frame;
    }

You have to set windowHeight Userdefaults value after window allocation in didFinishLauncing Method like

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[[NSUserDefaults standardUserDefaults] setFloat:self.window.frame.size.height forKey:@"windowHeight"];
二  Navigation Bar重疊的問題:

在頁面剛生成的時候 initWithNibName 函數 或者其他函數中加一句話:

        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
            self.edgesForExtendedLayout = UIRectEdgeNone;
        }
顯示方式就和IOS6 一致了。



如果有什么問題,請留言。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM