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

来源:互联网 发布:智慧课堂软件 编辑:程序博客网 时间:2024/06/06 20:48

在使用cordova6.0的过程中,编译好的APP运行在IOS7+系统上默认是与状态栏重叠的,而运行在IOS6及老版本中时是于状态栏分离的。

   解决办法如下:

   把文件MainViewController.m中的方法viewWillAppear进行相关修改如下。 作用是更改view的边界,使其下移20px,刚好是状态栏的高度。


- (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)      {          CGRect viewBounds=[self.webView  bounds];          viewBounds.origin.y=20;          viewBounds.size.height=viewBounds.size.height-20;          self.webView.frame=viewBounds;      }        [super viewWillAppear:animated];  }  

另外有一个奇怪的现象就是当,我在html页面内调用系统相机以后再返回或者着全屏播放视频再返回时,整个页面底部会有白色的空白控件,用调试工具查看后空白区域的高度是20px.该如何解决?

  由于整个cordova项目相当于一个页面的应用,不同的模块聚集在一起,所以当当前屏幕消失后(比如进入系统相机拍照页面)再出现的时候,还是会执行上面的代码,所以界面高度再次减少20px.

解决方法如下: 在MainViewController.m中添加如下代码:

-(void)viewWillDisappear:(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 viewWillDisappear:animated];}  
这样就可以。
阅读全文
0 0