Reputation: 33297
How do I prevent that my iPhone app overlaps my app? I want that the app screen starts below the status bar as is was in previous versions of iOS prior to iOS7.
The following image shows an example of a demo app where the app is overlapped by the status bar as marked with blue.
Upvotes: 0
Views: 1851
Reputation: 988
I know you tagged Cordova but if you have access to the ViewController that the Cordova content is displayed in then add the following within viewDidLoad.
if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
{
self.edgesForExtendedLayout = UIRectEdgeNone;
}
Rather than checking system versions you should test for functionality within that version of iOS.
Upvotes: 0
Reputation: 158
You can try create a category like this
#define SYSTEM_VERSION_OF_DEVICE_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
@implementation UIViewController (iOS7)
{
-(void)viewDidLayoutSubviews
{
if (!SYSTEM_VERSION_OF_DEVICE_LESS_THAN(@"7.0"))
{
CGRect viewBounds=self.view.bounds;
CGFloat topBarOffset=self.topLayoutGuide.length;
viewBounds.origin.y=topBarOffset*-1;
self.view.bounds=viewBounds;
}
}
@end
Upvotes: 0
Reputation: 12952
You can use the Cordova plugin StatusBarPlugin to change the status bar overlay. You can set the method below to start the app below the status bar in iOS7:
StatusBar.overlaysWebView(false);
If you are using phonegap-build you can include StatusBarPlugin directly
Or you can also do this directly in Objective-C in MainViewController.m by offsetting the webview by 20px:
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
CGRect appView = [self.webView bounds];
appView.origin.y = 20;
appView.size.height = appView.size.height - 20;
self.webView.frame = appView;
}
Upvotes: 2