UICollectionView与ContentInset不滚动一路下跌 [英] UICollectionView with ContentInset is not Scrolling all the Way Down

查看:745
本文介绍了UICollectionView与ContentInset不滚动一路下跌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置UICollectionView的内容插图:

I am setting the content inset of a UICollectionView:

[_collectionView setContentInset:UIEdgeInsetsMake(0.f, 0.f, 100.f, 0.f)];

然后我编程滚动一路用这种方法的UICollectionView的底部:

Then I am scrolling programmatically all the way to the bottom of the UICollectionView with 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];
}

据向下滚动,但它是无视contentInset,这意味着最后细胞是指定的内容插入如下:

It is scrolling down, but it is ignoring the contentInset, meaning that the last cells are below the specified content inset:


左边的图像,显​​示现在它是如何出现在视图也出现了。在右边的图像,我手动滚动进一步下降到最后的消息。

The left image, shows how it appear now after the view did appear. In the right image, I manually scrolled further down to the last message.

我使用的自动版式,任何想法,为什么出现这种情况?

I am using AutoLayout, any ideas why this happens?

编辑:

下面是IB设置的截图:

Here is a screenshot of the IB setup:

推荐答案

今天,一个偶然的机会我发现了解决方案!

Today, by chance I discovered the solution!

选择您的视图控制器,并取消选中调整滚动查看插图。

Select your view controller and uncheck the option "Adjust Scroll View Insets".

通过选中此选项,iOS不自动调整视图的插图(也可能是它的子视图),这引起了问题,我......取消选中它,并配置您的滚动插图这样的编程方式:

With this option unchecked, iOS does not automatically adjust your insets of the view (and probably its subviews), which caused the problems for me ... Uncheck it and configure your scroll insets like this programmatically:

- (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)];
}

这篇关于UICollectionView与ContentInset不滚动一路下跌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆