Skip to content

Commit

Permalink
Calculates the offset only when needed in views distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
gobetti committed Jul 8, 2016
1 parent 1eb3cd3 commit 7fb13db
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions Masonry/NSArray+MASAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,18 @@ - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedItemLength:(
for (int i = 0; i < self.count; i++) {
MAS_VIEW *v = self[i];
[v mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.equalTo(@(fixedItemLength));
if (prev) {
CGFloat offset = (1-(i/((CGFloat)self.count-1)))*(fixedItemLength+leadSpacing)-i*tailSpacing/(((CGFloat)self.count-1));
make.width.equalTo(@(fixedItemLength));
if (i == self.count - 1) {//last one
make.right.equalTo(tempSuperView).offset(-tailSpacing);
}
else {
CGFloat offset = (1-(i/((CGFloat)self.count-1)))*(fixedItemLength+leadSpacing)-i*tailSpacing/(((CGFloat)self.count-1));
make.right.equalTo(tempSuperView).multipliedBy(i/((CGFloat)self.count-1)).with.offset(offset);
}
}
else {//first one
make.left.equalTo(tempSuperView).offset(leadSpacing);
make.width.equalTo(@(fixedItemLength));
}
}];
prev = v;
Expand All @@ -122,19 +121,18 @@ - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedItemLength:(
for (int i = 0; i < self.count; i++) {
MAS_VIEW *v = self[i];
[v mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.equalTo(@(fixedItemLength));
if (prev) {
CGFloat offset = (1-(i/((CGFloat)self.count-1)))*(fixedItemLength+leadSpacing)-i*tailSpacing/(((CGFloat)self.count-1));
make.height.equalTo(@(fixedItemLength));
if (i == self.count - 1) {//last one
make.bottom.equalTo(tempSuperView).offset(-tailSpacing);
}
else {
CGFloat offset = (1-(i/((CGFloat)self.count-1)))*(fixedItemLength+leadSpacing)-i*tailSpacing/(((CGFloat)self.count-1));
make.bottom.equalTo(tempSuperView).multipliedBy(i/((CGFloat)self.count-1)).with.offset(offset);
}
}
else {//first one
make.top.equalTo(tempSuperView).offset(leadSpacing);
make.height.equalTo(@(fixedItemLength));
}
}];
prev = v;
Expand Down

0 comments on commit 7fb13db

Please sign in to comment.