Skip to content
This repository has been archived by the owner on Aug 14, 2019. It is now read-only.

Commit

Permalink
Merge pull request #644 from evilstudios/develop
Browse files Browse the repository at this point in the history
fix #480: scrollToBottomAnimated: fix long message handling
  • Loading branch information
jessesquires committed Dec 19, 2014
2 parents 16c42a1 + 6a04d75 commit d6c9dd0
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,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:UICollectionViewScrollPositionTop
atScrollPosition:position
animated:animated];
}

Expand Down

0 comments on commit d6c9dd0

Please sign in to comment.