Skip to content

Commit 8ce813e

Browse files
肖睿肖睿
肖睿
authored and
肖睿
committed
update
1 parent d024e43 commit 8ce813e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

XRWaterfallLayout/XRWaterfallLayout.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ - (void)prepareLayout {
7676

7777
//计算collectionView的contentSize
7878
- (CGSize)collectionViewContentSize {
79-
__block NSNumber *maxColumn = @0;
79+
__block NSNumber *maxIndex = @0;
8080
//遍历字典,找出最长的那一列
8181
[self.maxYDic enumerateKeysAndObjectsUsingBlock:^(NSNumber *key, NSNumber *obj, BOOL *stop) {
82-
if ([self.maxYDic[maxColumn] floatValue] < obj.floatValue) {
83-
maxColumn = key;
82+
if ([self.maxYDic[maxIndex] floatValue] < obj.floatValue) {
83+
maxIndex = key;
8484
}
8585
}];
8686

8787
//collectionView的contentSize.height就等于最长列的最大y值+下内边距
88-
return CGSizeMake(0, [self.maxYDic[maxColumn] floatValue] + self.sectionInset.bottom);
88+
return CGSizeMake(0, [self.maxYDic[maxIndex] floatValue] + self.sectionInset.bottom);
8989
}
9090

9191
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
@@ -107,24 +107,24 @@ - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSInde
107107
}
108108

109109
//找出最短的那一列
110-
__block NSNumber *minColumn = @0;
110+
__block NSNumber *minIndex = @0;
111111
[self.maxYDic enumerateKeysAndObjectsUsingBlock:^(NSNumber *key, NSNumber *obj, BOOL *stop) {
112-
if ([self.maxYDic[minColumn] floatValue] > obj.floatValue) {
113-
minColumn = key;
112+
if ([self.maxYDic[minIndex] floatValue] > obj.floatValue) {
113+
minIndex = key;
114114
}
115115
}];
116116

117117
//根据最短列的列数计算item的x值
118-
CGFloat itemX = self.sectionInset.left + (self.columnSpacing + itemWidth) * minColumn.integerValue;
118+
CGFloat itemX = self.sectionInset.left + (self.columnSpacing + itemWidth) * minIndex.integerValue;
119119

120120
//item的y值 = 最短列的最大y值 + 行间距
121-
CGFloat itemY = [self.maxYDic[minColumn] floatValue] + self.rowSpacing;
121+
CGFloat itemY = [self.maxYDic[minIndex] floatValue] + self.rowSpacing;
122122

123123
//设置attributes的frame
124124
attributes.frame = CGRectMake(itemX, itemY, itemWidth, itemHeight);
125125

126126
//更新字典中的最大y值
127-
self.maxYDic[minColumn] = @(CGRectGetMaxY(attributes.frame));
127+
self.maxYDic[minIndex] = @(CGRectGetMaxY(attributes.frame));
128128

129129
return attributes;
130130
}

0 commit comments

Comments
 (0)