Created
September 13, 2013 18:18
-
-
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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