iOS7 Phonegap / Cordova statusbar fix

Freitag, 31. Januar 2014


Since Apple has release the complete new iOS7 to public you may have some trouble with your phonegap apps. The reason is simple: the statusbar is not a reserved area anymore. It got a transparent bar with a 20px height.

It seems a simple thing but it is going to annoy you and especially your users!
Here is a simple trick to fix your application again, there might be other solutions to solve it in javascript within your application but I prefer the Objective-C way. If you had the app running as a website you wouldn't have to apply any changes.

Just replace the existing viewWillAppear function in your MainViewController.m, rebuild and you're done.

// Fix for shrinking screen on Camera, Camera-Roll, InAppBrowser and more...
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.
    //Lower screen 20px on ios 7
    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];
}