Skip to content

Commit

Permalink
Merge pull request #100 from joshleibsly/develop
Browse files Browse the repository at this point in the history
Fix for issue when layout is rotated
  • Loading branch information
chiahsien committed May 15, 2015
2 parents ba82094 + 523160b commit 2731fe9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions CHTCollectionViewWaterfallLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ - (CGFloat)itemWidthInSectionAtIndex:(NSInteger)section {
} else {
sectionInset = self.sectionInset;
}
CGFloat width = self.collectionView.frame.size.width - sectionInset.left - sectionInset.right;
CGFloat width = self.collectionView.bounds.size.width - sectionInset.left - sectionInset.right;
NSInteger columnCount = [self columnCountForSection:section];

CGFloat columnSpacing = self.minimumColumnSpacing;
Expand Down Expand Up @@ -259,7 +259,7 @@ - (void)prepareLayout {
sectionInset = self.sectionInset;
}

CGFloat width = self.collectionView.frame.size.width - sectionInset.left - sectionInset.right;
CGFloat width = self.collectionView.bounds.size.width - sectionInset.left - sectionInset.right;
NSInteger columnCount = [self columnCountForSection:section];
CGFloat itemWidth = CHTFloorCGFloat((width - (columnCount - 1) * columnSpacing) / columnCount);

Expand All @@ -286,7 +286,7 @@ - (void)prepareLayout {
attributes = [UICollectionViewLayoutAttributes layoutAttributesForSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withIndexPath:[NSIndexPath indexPathForItem:0 inSection:section]];
attributes.frame = CGRectMake(headerInset.left,
top,
self.collectionView.frame.size.width - (headerInset.left + headerInset.right),
self.collectionView.bounds.size.width - (headerInset.left + headerInset.right),
headerHeight);

self.headersAttribute[@(section)] = attributes;
Expand Down Expand Up @@ -353,7 +353,7 @@ - (void)prepareLayout {
attributes = [UICollectionViewLayoutAttributes layoutAttributesForSupplementaryViewOfKind:CHTCollectionElementKindSectionFooter withIndexPath:[NSIndexPath indexPathForItem:0 inSection:section]];
attributes.frame = CGRectMake(footerInset.left,
top,
self.collectionView.frame.size.width - (footerInset.left + footerInset.right),
self.collectionView.bounds.size.width - (footerInset.left + footerInset.right),
footerHeight);

self.footersAttribute[@(section)] = attributes;
Expand Down
8 changes: 4 additions & 4 deletions CHTCollectionViewWaterfallLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class CHTCollectionViewWaterfallLayout : UICollectionViewLayout{
}else{
insets = self.sectionInset
}
let width:CGFloat = self.collectionView!.frame.size.width - sectionInset.left-sectionInset.right
let width:CGFloat = self.collectionView!.bounds.size.width - sectionInset.left-sectionInset.right
let spaceColumCount:CGFloat = CGFloat(self.columnCount-1)
return floor((width - (spaceColumCount*self.minimumColumnSpacing)) / CGFloat(self.columnCount))
}
Expand Down Expand Up @@ -166,7 +166,7 @@ class CHTCollectionViewWaterfallLayout : UICollectionViewLayout{
sectionInsets = self.sectionInset
}

let width = self.collectionView!.frame.size.width - sectionInset.left - sectionInset.right
let width = self.collectionView!.bounds.size.width - sectionInset.left - sectionInset.right
let spaceColumCount = CGFloat(self.columnCount-1)
let itemWidth = floor((width - (spaceColumCount*self.minimumColumnSpacing)) / CGFloat(self.columnCount))

Expand All @@ -182,7 +182,7 @@ class CHTCollectionViewWaterfallLayout : UICollectionViewLayout{

if heightHeader > 0 {
attributes = UICollectionViewLayoutAttributes(forSupplementaryViewOfKind: CHTCollectionElementKindSectionHeader, withIndexPath: NSIndexPath(forRow: 0, inSection: section))
attributes.frame = CGRectMake(0, top, self.collectionView!.frame.size.width, heightHeader)
attributes.frame = CGRectMake(0, top, self.collectionView!.bounds.size.width, heightHeader)
self.headersAttributes.setObject(attributes, forKey: (section))
self.allItemAttributes.addObject(attributes)

Expand Down Expand Up @@ -235,7 +235,7 @@ class CHTCollectionViewWaterfallLayout : UICollectionViewLayout{

if footerHeight > 0 {
attributes = UICollectionViewLayoutAttributes(forSupplementaryViewOfKind: CHTCollectionElementKindSectionFooter, withIndexPath: NSIndexPath(forItem: 0, inSection: section))
attributes.frame = CGRectMake(0, top, self.collectionView!.frame.size.width, footerHeight)
attributes.frame = CGRectMake(0, top, self.collectionView!.bounds.size.width, footerHeight)
self.footersAttributes.setObject(attributes, forKey: section)
self.allItemAttributes.addObject(attributes)
top = CGRectGetMaxY(attributes.frame)
Expand Down

0 comments on commit 2731fe9

Please sign in to comment.