@@ -76,16 +76,16 @@ - (void)prepareLayout {
76
76
77
77
// 计算collectionView的contentSize
78
78
- (CGSize)collectionViewContentSize {
79
- __block NSNumber *maxColumn = @0 ;
79
+ __block NSNumber *maxIndex = @0 ;
80
80
// 遍历字典,找出最长的那一列
81
81
[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;
84
84
}
85
85
}];
86
86
87
87
// 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 );
89
89
}
90
90
91
91
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath : (NSIndexPath *)indexPath {
@@ -107,24 +107,24 @@ - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSInde
107
107
}
108
108
109
109
// 找出最短的那一列
110
- __block NSNumber *minColumn = @0 ;
110
+ __block NSNumber *minIndex = @0 ;
111
111
[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;
114
114
}
115
115
}];
116
116
117
117
// 根据最短列的列数计算item的x值
118
- CGFloat itemX = self.sectionInset .left + (self.columnSpacing + itemWidth) * minColumn .integerValue ;
118
+ CGFloat itemX = self.sectionInset .left + (self.columnSpacing + itemWidth) * minIndex .integerValue ;
119
119
120
120
// item的y值 = 最短列的最大y值 + 行间距
121
- CGFloat itemY = [self .maxYDic[minColumn ] floatValue ] + self.rowSpacing ;
121
+ CGFloat itemY = [self .maxYDic[minIndex ] floatValue ] + self.rowSpacing ;
122
122
123
123
// 设置attributes的frame
124
124
attributes.frame = CGRectMake (itemX, itemY, itemWidth, itemHeight);
125
125
126
126
// 更新字典中的最大y值
127
- self.maxYDic [minColumn ] = @(CGRectGetMaxY (attributes.frame ));
127
+ self.maxYDic [minIndex ] = @(CGRectGetMaxY (attributes.frame ));
128
128
129
129
return attributes;
130
130
}
0 commit comments