Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 status bar and self.view.frame and self.view.bounds

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)];
}

enter image description here

like image 458
Mr Ordinary Avatar asked Sep 20 '13 04:09

Mr Ordinary


1 Answers

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.

like image 67
Nandha Avatar answered Sep 28 '22 16:09

Nandha