自动调整UICollectionView高度以调整其内容大小 [英] Autoresize UICollectionView height to adjust to its content size

查看:4927
本文介绍了自动调整UICollectionView高度以调整其内容大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UICollectionView,一个在集合视图中创建新单元格的按钮。我希望UICollectionView根据它的内容大小调整它的大小(当有一个或两个单元格时,那么UICollectionView很短,如果有很多单元格UICollectionView足够大)。

I have a UICollectionView, a button that creates a new cell in collection view. And I want UICollectionView to adjust it's size according to it's content size (when there are one or two cells then UICollectionView is short, if there are a lot of cell UICollectionView is big enough).

我知道如何获取内容大小:

I know how to get content size:

collectionView.collectionViewLayout.collectionViewContentSize

但我不知道在哪里使用这个值。如果有人帮我弄清楚如何让UICollectionView自动调整它的高度,我将不胜感激。

But I have no idea where to use this value. I would appreciate if somebody help me to figure out how to make UICollectionView auto adjust it's height.

UPD:
我在GitHub上发布了一个描述问题: https://github.com/avokin/PostViewer

推荐答案

我不认为内容大小是你所追求的。我想你想要调整集合视图消耗的屏幕空间量,对吧?这将需要调整框架。内容大小包括屏幕外(滚动)区域以及屏幕视图。

I don't think content size is what you're after. I think you're wanting to adjust the amount of screen real estate consumed by the collection view, right? That's going to require adjustment of the frame. The content size includes the off-screen (scrolling) area as well as the on screen view.

我不知道任何会阻止你改变即时帧大小:

I don't know of anything that would prevent you from just changing the frame size on the fly:

collectionView.frame = CGRectMake (x,y,w,h);
[collectionView reloadData];

如果我理解正确的话。

这篇关于自动调整UICollectionView高度以调整其内容大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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