解决在iphone(ios7)中状态栏(Status bar)会覆盖(overlap)在软件(view)上的问题

来源:互联网 发布:科比2001年总决赛数据 编辑:程序博客网 时间:2024/06/05 21:07
做了个软件,在android下显示正常,在iphone中最顶部的statusbar为何会覆盖在软件上方?如图:




解决办法:
第一种:
如果允许,隐藏状态栏。

在xcode中找到Resources/xxx-Info.plist文件,
添加2个属性:

<key>UIStatusBarHidden</key><true/><key>UIViewControllerBasedStatusBarAppearance</key><false/>


第二种:
在xcode中找到Classes/MainViewController.m文件
修改- (void)viewWillAppear:(BOOL)animated方法,

注意添加一个sizeWasAdjusted变量,用于表示view是否已经调整过,否则每次从其他app返回自己的app时每次都会执行-20,导致你的app最下面产生一条白带。

bool sizeWasAdjusted = false;- (void)viewWillAppear:(BOOL)animated{    // View defaults to full size.  If you want to customize the view's size, or its subviews (e.g. webView),    // you can do so here.    if (!sizeWasAdjusted && [[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {        CGRect viewBounds = [self.webView bounds];        viewBounds.origin.y = 20;        viewBounds.size.height = viewBounds.size.height - 20;        self.webView.frame = viewBounds;        sizeWasAdjusted = true;    }    [super viewWillAppear:animated];}