我正在设置UICollectionView的内容插入:
[_collectionView setContentInset:UIEdgeInsetsMake(0.f, 0.f, 100.f, 0.f)];
然后我使用该方法以编程方式滚动到UICollectionView的底部:
- (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];
}
它正在向下滚动,但忽略了contentInset,这意味着最后的单元格在指定的content inset下方:
左边的图像显示了它现在的外观。在右边的图像中,我手动向下滚动到了最后一条消息。
我正在使用AutoLayout,有什么想法是为什么会发生这种情况吗?
编辑:
这里是IB设置的截图: