gpt4 book ai didi

ios - 带有 ContentInset 的 UICollectionView 没有一直向下滚动

转载 作者:IT王子 更新时间:2023-10-29 08:21:50 25 4
gpt4 key购买 nike

我正在设置 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,这意味着最后一个单元格位于指定的内容插图下方:

enter image description here左图显示了 View 出现后现在的样子。在右图中,我手动向下滚动到最后一条消息。

我正在使用 AutoLayout,知道为什么会这样吗?

编辑:

这是 IB 设置的屏幕截图: enter image description here

最佳答案

今天偶然发现了解决方法!

选择您的 View Controller 并取消选中“调整 ScrollView 插入”选项。

enter image description here

如果未选中此选项,iOS 不会自动调整 View 的插图(可能还有它的 subview ),这导致了我的问题......取消选中它并以编程方式配置滚动插图:

- (void)configureInsetsOfCollectionView
{
[_collectionView setContentInset: UIEdgeInsetsMake(self.navigationController.navigationBar.bounds.size.height + [UIApplication sharedApplication].statusBarFrame.size.height + DEFAULT_SPACING, 0.f, _keyboardHeight + _toolbar.bounds.size.height + DEFAULT_SPACING, 0.f)];
[_collectionView setScrollIndicatorInsets:UIEdgeInsetsMake(self.navigationController.navigationBar.bounds.size.height + [UIApplication sharedApplication].statusBarFrame.size.height, 0.f, _keyboardHeight + _toolbar.bounds.size.height, 0.f)];
}

关于ios - 带有 ContentInset 的 UICollectionView 没有一直向下滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23993409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com