Skip to content
Open
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
30 changes: 24 additions & 6 deletions Masonry/MASViewConstraint.m
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,17 @@ - (void)setSecondViewAttribute:(id)secondViewAttribute {

- (MASConstraint * (^)(MASLayoutPriority))priority {
return ^id(MASLayoutPriority priority) {
NSAssert(!self.hasBeenInstalled,
@"Cannot modify constraint priority after it has been installed");

self.layoutPriority = priority;
if (!self.hasBeenInstalled) {
self.layoutPriority = priority;
} else {
NSAssert(priority != UILayoutPriorityRequired
&& self.layoutConstraint.priority != UILayoutPriorityRequired,
@"the priority cannot be changed from/to NSLayoutPriorityRequired");
if (priority != UILayoutPriorityRequired
&& self.layoutConstraint.priority != UILayoutPriorityRequired){
self.layoutConstraint.priority = priority;
}
}
return self;
};
}
Expand Down Expand Up @@ -359,8 +366,20 @@ - (void)install {
existingConstraint = [self layoutConstraintSimilarTo:layoutConstraint];
}
if (existingConstraint) {
// just update the constant
// update the constant
existingConstraint.constant = layoutConstraint.constant;

// update the priority if possible
if (existingConstraint.priority != layoutConstraint.priority) {
NSAssert(existingConstraint.priority != UILayoutPriorityRequired
&& layoutConstraint.priority != UILayoutPriorityRequired,
@"the priority cannot be changed from/to NSLayoutPriorityRequired");
if (existingConstraint.priority != UILayoutPriorityRequired
&& layoutConstraint.priority != UILayoutPriorityRequired){
existingConstraint.priority = layoutConstraint.priority;
}
}

self.layoutConstraint = existingConstraint;
} else {
[self.installedView addConstraint:layoutConstraint];
Expand All @@ -382,7 +401,6 @@ - (MASLayoutConstraint *)layoutConstraintSimilarTo:(MASLayoutConstraint *)layout
if (existingConstraint.secondAttribute != layoutConstraint.secondAttribute) continue;
if (existingConstraint.relation != layoutConstraint.relation) continue;
if (existingConstraint.multiplier != layoutConstraint.multiplier) continue;
if (existingConstraint.priority != layoutConstraint.priority) continue;

return (id)existingConstraint;
}
Expand Down