技術分享

phonegap 2.9 在ios 7 上避免 statusbar 蓋住上方header的解決方法

開啟 MainViewController.m 找到下面的語法viewWillAppear,加進去如以下所示即可:

- (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.
    // Lower screen 20px on ios 7
    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];
}

至於phonegap 2.9以外的其他版本,筆者就不知道了!

這樣的效果會在ios7上status bar 變成白色的底,黑色的字哦iOS Simulator Screen shot 2014.4.17 下午2.48.27