Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Masonry/MASConstraintMaker.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ - (id)initWithView:(MAS_VIEW *)view {

- (NSArray *)install {
if (self.removeExisting) {
NSArray *installedConstraints = [MASViewConstraint installedConstraintsForView:self.view];
for (MASConstraint *constraint in installedConstraints) {
[constraint uninstall];
}
[self.view mas_removeExistingConstraints];
}
NSArray *constraints = self.constraints.copy;
for (MASConstraint *constraint in constraints) {
Expand Down
5 changes: 5 additions & 0 deletions Masonry/NSArray+MASAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ typedef NS_ENUM(NSUInteger, MASAxisType) {
*/
- (NSArray *)mas_remakeConstraints:(void (NS_NOESCAPE ^)(MASConstraintMaker *make))block;

/**
* Removes all constraints previously installed on each view in the callee.
*/
- (void)mas_removeExistingConstraints;

/**
* distribute with fixed spacing
*
Expand Down
7 changes: 7 additions & 0 deletions Masonry/NSArray+MASAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block {
return constraints;
}

- (void)mas_removeExistingConstraints {
for (MAS_VIEW *view in self) {
NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views");
[view mas_removeExistingConstraints];
}
}

- (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedSpacing:(CGFloat)fixedSpacing leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing {
if (self.count < 2) {
NSAssert(self.count>1,@"views to distribute need to bigger than one");
Expand Down
5 changes: 5 additions & 0 deletions Masonry/View+MASAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,9 @@
*/
- (NSArray *)mas_remakeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *make))block;

/**
* Removes all constraints previously installed on the callee view.
*/
- (void)mas_removeExistingConstraints;

@end
8 changes: 8 additions & 0 deletions Masonry/View+MASAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "View+MASAdditions.h"
#import "MASViewConstraint.h"
#import <objc/runtime.h>

@implementation MAS_VIEW (MASAdditions)
Expand Down Expand Up @@ -34,6 +35,13 @@ - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block {
return [constraintMaker install];
}

- (void)mas_removeExistingConstraints {
NSArray *installedConstraints = [MASViewConstraint installedConstraintsForView:self];
for (MASConstraint *constraint in installedConstraints) {
[constraint uninstall];
}
}

#pragma mark - NSLayoutAttribute properties

- (MASViewAttribute *)mas_left {
Expand Down
4 changes: 4 additions & 0 deletions Masonry/View+MASShorthandAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
- (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block;
- (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block;
- (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block;
- (void)removeExistingConstraints;

@end

Expand Down Expand Up @@ -110,6 +111,9 @@ MAS_ATTR_FORWARD(centerYWithinMargins);
return [self mas_remakeConstraints:block];
}

- (void)removeExistingConstraints {
[self mas_removeExistingConstraints];
}
@end

#endif