1. 程式人生 > >解決Cordova開發的iOS的app介面被狀態列覆蓋

解決Cordova開發的iOS的app介面被狀態列覆蓋

   在使用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];
    
    
    
}

這樣就ok了。