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

阅读更多
做了个软件,在android下显示正常,在iphone中最顶部的statusbar为何会覆盖在软件上方?如图:

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


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

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

UIStatusBarHidden

UIViewControllerBasedStatusBarAppearance


第二种:
在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];
}



  • 解决在iphone(ios7)中状态栏(Status bar)会覆盖(overlap)在软件(view)上的问题_第2张图片
  • 大小: 14 KB
  • 查看图片附件

你可能感兴趣的:(ios)