I set the content in a UICollectionView:
[_collectionView setContentInset:UIEdgeInsetsMake(0.f, 0.f, 100.f, 0.f)]
Then I scroll programmatically down to the bottom of the UICollectionView using this method:
- (void)scrollToLastMessageAnimated:(BOOL)animated; { if (_messages.count == 0) { return; } NSUInteger indexOfLastSection = _messagesBySections.count - 1; NSInteger indexOfMessageInLastSection = [_messagesBySections[indexOfLastSection] count] - 1; NSIndexPath *path = [NSIndexPath indexPathForItem:indexOfMessageInLastSection inSection:indexOfLastSection]; [_collectionView scrollToItemAtIndexPath:path atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:animated]; }
It scrolls down, but ignores the value of the contentInset, which means that the last cells are below the specified content insert:
The left image shows how it appeared after viewing. On the correct image, I manually scrolled on to the last message.
I use AutoLayout, any ideas why this is happening?
EDIT:
Here is a screenshot of IB setup: 
ios objective-c autolayout scroll uicollectionview
Ben marten
source share