Skip to content

Commit

Permalink
improve layout for smaller cells
Browse files Browse the repository at this point in the history
in some cases, `Top` alignment is best - this commit handles those cases
  • Loading branch information
toblerpwn committed Nov 26, 2014
1 parent 28b1789 commit 6a04d75
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,20 @@ - (void)scrollToBottomAnimated:(BOOL)animated
return;
}

// if last object is huge, use UICollectionViewScrollPositionBottom for better appearance
// else use Top
NSInteger finalRow = MAX(0, [self.collectionView numberOfItemsInSection:0] - 1);
NSIndexPath *finalIndexPath = [NSIndexPath indexPathForItem:finalRow
inSection:0];
CGSize finalCellSize = [self.collectionView.collectionViewLayout sizeForItemAtIndexPath:finalIndexPath];

CGFloat maxHeight = CGRectGetHeight(self.collectionView.bounds) - self.collectionView.contentInset.top - CGRectGetHeight(self.inputToolbar.bounds);

BOOL hugeCell = (maxHeight < finalCellSize.height);
UICollectionViewScrollPosition position = (hugeCell) ? UICollectionViewScrollPositionBottom : UICollectionViewScrollPositionTop;

[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:items - 1 inSection:0]
atScrollPosition:UICollectionViewScrollPositionBottom
atScrollPosition:position
animated:animated];
}

Expand Down

0 comments on commit 6a04d75

Please sign in to comment.