I recently released an iOS6 app, and I need to update it for iOS 7. The new status bar is a bit of an issue. The frame/bounds of self.view seem to have changed (+20 points) and I use self.view.bounds to determine the placement of some elements. I have been looking at some solutions. Basically I need to update the app while still supporting the iOS 6 status bar. Is there a best practice for this?
The code below seems to work to detect an iOS 7 device and shift the content into position, but also causes other issues. Anyway I am not confident that this is the best way.
if([[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."][0] intValue] >= 7) {
CGRect statusBarViewRect = [[UIApplication sharedApplication] statusBarFrame];
float heightPadding = statusBarViewRect.size.height+self.navigationController.navigationBar.frame.size.height;
[myContentView setFrame:CGRectMake(0, heightPadding, self.view.frame.size.width, self.view.frame.size.height - heightPadding)];
}
You can achieve this by implementing new property called edgesForExtendedLayout in iOS7 SDK. Please add the following code to achieve this,
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
You need add the above code in your -(void)viewDidLoad method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With