简体   繁体   English

无法动态更改集合视图内容大小?

[英]Can not change collection view content size dynamically?

I am trying to change a collection view content size with : 我正在尝试更改集合视图内容大小:

collectionView.contentSize.height = 1.25*collectionView.contentSize.height

(or any variation of this line of code) (或此行代码的任何变体)

Since we are adding views at the bottom of its content, after the last cell. 由于我们在最后一个单元格后面的内容底部添加了视图。

This line of code will not work, and the bottom views are out of screen, you can scroll only to the last cell (default height) 这行代码不起作用,底部视图不在屏幕上,您只能滚动到最后一个单元格(默认高度)

I have tried to read any answer here, non was specific/solve the problem. 我试图在这里阅读任何答案,非具体/解决问题。

How can one simply change the content height of a collection ? 如何只改变集合的内容高度?

The content size of your collection view is calculated by its 'collectionViewLayout'. 集合视图的内容大小由其“collectionViewLayout”计算。 If you want to change the content size then you'll have to subclass a collection view layout, and override "collectionViewContentSize", and return whatever size you want. 如果要更改内容大小,则必须子类化集合视图布局,并覆盖“collectionViewContentSize”,并返回所需的任何大小。 It would probably look something like this (assuming you are using a flow layout): 它可能看起来像这样(假设您正在使用流布局):

- (CGSize)collectionViewContentSize {
    CGSize size = [super collectionViewContentSize];
    size.height += yourCustomView.frame.size.height;
    return size;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM