Skip to content

Commit

Permalink
Add new method to recursively remove all constraints from a view
Browse files Browse the repository at this point in the history
  • Loading branch information
smileyborg committed Aug 27, 2013
1 parent 29c10b2 commit d0c3060
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
13 changes: 1 addition & 12 deletions Example/Example/ALViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ - (void)setupDemo5
*/
- (void)changeConstraintDemo
{
[self removeAllConstraintsFromViewAndSubviews:self.view];
[self.view removeAllConstraintsFromViewAndSubviews];
[self.containerView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(10.0f, 10.0f, 10.0f, 10.0f)];

self.constraintDemo++;
Expand Down Expand Up @@ -275,17 +275,6 @@ - (void)changeConstraintDemo
}
}

/**
Recursive helper method to remove all constraints from a given view and its subviews.
*/
- (void)removeAllConstraintsFromViewAndSubviews:(UIView *)view
{
[UIView removeConstraints:view.constraints];
for (UIView *subview in view.subviews) {
[self removeAllConstraintsFromViewAndSubviews:subview];
}
}

#pragma mark Property Accessors

- (UIView *)containerView
Expand Down
3 changes: 3 additions & 0 deletions Source/UIView+AutoLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ typedef void(^ALConstraintsBlock)(void); // a block of method calls to the UI
/** Removes the given constraints from the views they have been added to. */
+ (void)removeConstraints:(NSArray *)constraints;

/** Recursively removes all constraints from the view and its subviews. */
- (void)removeAllConstraintsFromViewAndSubviews;


/** Centers the view in its superview. */
- (NSArray *)autoCenterInSuperview;
Expand Down
11 changes: 11 additions & 0 deletions Source/UIView+AutoLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ + (void)removeConstraints:(NSArray *)constraints
}
}

/**
Recursively removes all constraints from the view and its subviews.
*/
- (void)removeAllConstraintsFromViewAndSubviews
{
[UIView removeConstraints:self.constraints];
for (UIView *subview in self.subviews) {
[subview removeAllConstraintsFromViewAndSubviews];
}
}

/**
Centers the view in its superview.
Expand Down

0 comments on commit d0c3060

Please sign in to comment.