Skip to content

Commit

Permalink
Merge branch 'release/0.9.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
chiahsien committed May 24, 2017
2 parents 94755eb + 3c60b60 commit 37478b4
Show file tree
Hide file tree
Showing 8 changed files with 331 additions and 304 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ profile
*.moved-aside
DerivedData
.idea/

# Carthage
Carthage/
28 changes: 23 additions & 5 deletions CHTCollectionViewWaterfallLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,12 @@ - (void)prepareLayout {
*/
CGFloat footerHeight;
NSUInteger columnIndex = [self longestColumnIndexInSection:section];
top = [self.columnHeights[section][columnIndex] floatValue] - minimumInteritemSpacing + sectionInset.bottom;

if (((NSArray *)self.columnHeights[section]).count > 0) {
top = [self.columnHeights[section][columnIndex] floatValue] - minimumInteritemSpacing + sectionInset.bottom;
} else {
top = 0;
}

if ([self.delegate respondsToSelector:@selector(collectionView:layout:heightForFooterInSection:)]) {
footerHeight = [self.delegate collectionView:self.collectionView layout:self heightForFooterInSection:section];
} else {
Expand Down Expand Up @@ -423,7 +427,9 @@ - (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
NSInteger i;
NSInteger begin = 0, end = self.unionRects.count;
NSMutableArray *attrs = [NSMutableArray array];
NSMutableDictionary *cellAttrDict = [NSMutableDictionary dictionary];
NSMutableDictionary *supplAttrDict = [NSMutableDictionary dictionary];
NSMutableDictionary *decorAttrDict = [NSMutableDictionary dictionary];

for (i = 0; i < self.unionRects.count; i++) {
if (CGRectIntersectsRect(rect, [self.unionRects[i] CGRectValue])) {
Expand All @@ -440,11 +446,23 @@ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
for (i = begin; i < end; i++) {
UICollectionViewLayoutAttributes *attr = self.allItemAttributes[i];
if (CGRectIntersectsRect(rect, attr.frame)) {
[attrs addObject:attr];
switch (attr.representedElementCategory) {
case UICollectionElementCategorySupplementaryView:
supplAttrDict[attr.indexPath] = attr;
break;
case UICollectionElementCategoryDecorationView:
decorAttrDict[attr.indexPath] = attr;
break;
case UICollectionElementCategoryCell:
cellAttrDict[attr.indexPath] = attr;
break;
}
}
}

return [NSArray arrayWithArray:attrs];
NSArray *result = [cellAttrDict.allValues arrayByAddingObjectsFromArray:supplAttrDict.allValues];
result = [result arrayByAddingObjectsFromArray:decorAttrDict.allValues];
return result;
}

- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
Expand Down
2 changes: 1 addition & 1 deletion CHTCollectionViewWaterfallLayout.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "CHTCollectionViewWaterfallLayout"
s.version = "0.9.5"
s.version = "0.9.6"
s.summary = "The waterfall (i.e., Pinterest-like) layout for UICollectionView."
s.homepage = "https://github.com/chiahsien/CHTCollectionViewWaterfallLayout"
s.screenshots = "https://raw.github.com/chiahsien/UICollectionViewWaterfallLayout/master/Screenshots/2-columns.png"
Expand Down
Loading

0 comments on commit 37478b4

Please sign in to comment.