Skip to content

Instantly share code, notes, and snippets.

@DrAma999
Created September 13, 2013 18:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DrAma999/6554189 to your computer and use it in GitHub Desktop.
Save DrAma999/6554189 to your computer and use it in GitHub Desktop.
Method to be used inside a VC subclass or VC abstract class to avoid the status bar overlapping feature in iOS7. Actually tested only for single VC not added in hierachy. To use it you should embed all your view subviews into another view called tankView. It should be called before the view controller views has the opportunity to layout its view.
//This should be added before the layout of the view
- (void) adaptToTopLayoutGuide {
//Check if we can get the top layoutguide
if (![self respondsToSelector:@selector(topLayoutGuide)]) {
return;
}
//tankView is a contaner view
NSArray * array = [self.tankView referencingConstraintsInSuperviews]; //<--For this method get the Autolayout Demistified Book Sample made by Erica Sadun
[self.view removeConstraints:array];
NSArray * constraintsVertical = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[topLayoutGuide]-0-[tankView]|" options:0 metrics:nil views:@{@"tankView": self.tankView, @"topLayoutGuide":self.topLayoutGuide}];
[self.view addConstraints:constraintsVertical];
NSArray * constraintsHorizontal = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[tankView]|" options:0 metrics:nil views:@{@"tankView": self.tankView}];
[self.view addConstraints:constraintsHorizontal];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment