【发布时间】:2014-07-22 12:06:34
【问题描述】:
我正在设置 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 设置的屏幕截图:
【问题讨论】:
-
你是如何设置底部约束的?这个问题很可能与集合视图的大小有关,而与内容插图几乎没有关系。
-
截屏以了解您添加的布局
-
我认为您的 _collectionView 高度是问题所在。您应该将高度设置为屏幕下方的视图
-
好的,我添加了我的 IB 设置的屏幕截图...见上文...
-
好吧,当消息在它下方滚动时,我想要 UIToolbar 的半透明效果。出于这个原因,UICollectionView 位于 UIToolBar 下方,我正在设置 contentInset。
标签: ios objective-c scroll uicollectionview autolayout