Committed by
GitHub
Merge pull request #362 from gobetti/views-distribution-optimization
Calculates the offset only when needed in views distribution
Showing
1 changed file
with
4 additions
and
6 deletions
@@ -99,19 +99,18 @@ | @@ -99,19 +99,18 @@ | ||
99 | for (int i = 0; i < self.count; i++) { | 99 | for (int i = 0; i < self.count; i++) { |
100 | MAS_VIEW *v = self[i]; | 100 | MAS_VIEW *v = self[i]; |
101 | [v mas_makeConstraints:^(MASConstraintMaker *make) { | 101 | [v mas_makeConstraints:^(MASConstraintMaker *make) { |
102 | + make.width.equalTo(@(fixedItemLength)); | ||
102 | if (prev) { | 103 | if (prev) { |
103 | - CGFloat offset = (1-(i/((CGFloat)self.count-1)))*(fixedItemLength+leadSpacing)-i*tailSpacing/(((CGFloat)self.count-1)); | ||
104 | - make.width.equalTo(@(fixedItemLength)); | ||
105 | if (i == self.count - 1) {//last one | 104 | if (i == self.count - 1) {//last one |
106 | make.right.equalTo(tempSuperView).offset(-tailSpacing); | 105 | make.right.equalTo(tempSuperView).offset(-tailSpacing); |
107 | } | 106 | } |
108 | else { | 107 | else { |
108 | + CGFloat offset = (1-(i/((CGFloat)self.count-1)))*(fixedItemLength+leadSpacing)-i*tailSpacing/(((CGFloat)self.count-1)); | ||
109 | make.right.equalTo(tempSuperView).multipliedBy(i/((CGFloat)self.count-1)).with.offset(offset); | 109 | make.right.equalTo(tempSuperView).multipliedBy(i/((CGFloat)self.count-1)).with.offset(offset); |
110 | } | 110 | } |
111 | } | 111 | } |
112 | else {//first one | 112 | else {//first one |
113 | make.left.equalTo(tempSuperView).offset(leadSpacing); | 113 | make.left.equalTo(tempSuperView).offset(leadSpacing); |
114 | - make.width.equalTo(@(fixedItemLength)); | ||
115 | } | 114 | } |
116 | }]; | 115 | }]; |
117 | prev = v; | 116 | prev = v; |
@@ -122,19 +121,18 @@ | @@ -122,19 +121,18 @@ | ||
122 | for (int i = 0; i < self.count; i++) { | 121 | for (int i = 0; i < self.count; i++) { |
123 | MAS_VIEW *v = self[i]; | 122 | MAS_VIEW *v = self[i]; |
124 | [v mas_makeConstraints:^(MASConstraintMaker *make) { | 123 | [v mas_makeConstraints:^(MASConstraintMaker *make) { |
124 | + make.height.equalTo(@(fixedItemLength)); | ||
125 | if (prev) { | 125 | if (prev) { |
126 | - CGFloat offset = (1-(i/((CGFloat)self.count-1)))*(fixedItemLength+leadSpacing)-i*tailSpacing/(((CGFloat)self.count-1)); | ||
127 | - make.height.equalTo(@(fixedItemLength)); | ||
128 | if (i == self.count - 1) {//last one | 126 | if (i == self.count - 1) {//last one |
129 | make.bottom.equalTo(tempSuperView).offset(-tailSpacing); | 127 | make.bottom.equalTo(tempSuperView).offset(-tailSpacing); |
130 | } | 128 | } |
131 | else { | 129 | else { |
130 | + CGFloat offset = (1-(i/((CGFloat)self.count-1)))*(fixedItemLength+leadSpacing)-i*tailSpacing/(((CGFloat)self.count-1)); | ||
132 | make.bottom.equalTo(tempSuperView).multipliedBy(i/((CGFloat)self.count-1)).with.offset(offset); | 131 | make.bottom.equalTo(tempSuperView).multipliedBy(i/((CGFloat)self.count-1)).with.offset(offset); |
133 | } | 132 | } |
134 | } | 133 | } |
135 | else {//first one | 134 | else {//first one |
136 | make.top.equalTo(tempSuperView).offset(leadSpacing); | 135 | make.top.equalTo(tempSuperView).offset(leadSpacing); |
137 | - make.height.equalTo(@(fixedItemLength)); | ||
138 | } | 136 | } |
139 | }]; | 137 | }]; |
140 | prev = v; | 138 | prev = v; |
-
Please register or login to post a comment