解决Cordova开发iOS的app界面被状态栏覆盖的问题

方法一:
先在Info.plist中添加:View controller-based status bar appearance 并将其值设置为NO。
在MainViewController.m实现类文件中修改viewWillAppear方法,修改内容如下:
作用是更改View的边界,使其下移20px,刚好是状态栏的高度。
- (void)viewWillAppear:(BOOL)animated
{
if([[[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;
}
[super viewWillAppear:animated];
}

如果程序涉及到打开系统相册或照相机功能时,需要在该类@implementation下声明一个变量,用来只让设置高度-20点代码运行一次,并修改刚才添加点if判断中的代码块,如:
int count = 1;
- (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([[[UIDevice currentDevice] systemVersion] floatValue] >= 7){
if(count != nil && count == 1){
CGRect viewBounds = [self.webView bounds];
viewBounds.origin.y = 20;
viewBounds.size.height = viewBounds.size.height-20;
self.webView.frame = viewBounds;
count -= 1;
}
}
[super viewWillAppear:animated];
}

方法二:
给index.html的body设置css样式:
padding-bottom:20px
而且这样还有一个好处就是状态栏可以透明。

推荐使用方法一。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值