如何确定UICollectionView高度具有FlowLayout [英] How to determine height of UICollectionView with FlowLayout

查看:116
本文介绍了如何确定UICollectionView高度具有FlowLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UICollectionView UICollectionViewFlowLayout ,我想计算出其含量的大小(返程在 intrinsicContentSize需要通过自动版式调整它的高度)

I've got an UICollectionView with an UICollectionViewFlowLayout, and i want to calculate its content size (for return in intrinsicContentSize needed for adjusting its height via AutoLayout).

的一个问题是:即使我有所有的细胞固定和相等的高度,我不知道有多少行/线已在 UICollectionView 。我还不能确定通过我的数据源中的项目数是计数,由于细胞重新presenting数据项宽度是变化的,所以结果不我在<$ C的一行的项目数$ C> UICollectionView 。

The problems is: Even if I have a fixed and equal height for all cells, I don't know how many "rows"/lines I have in the UICollectionView. I also can't determine that count by the number of items in my data source, since the cells representing the data items vary in width, so does consequently the number of items I have in one line of the UICollectionView.

因为我无法找到关于这一主题的任何暗示的官方文档和谷歌搜索没有给我带来任何进一步的,任何帮助和想法将AP preciated非常多。

Since I couldn't find any hints on this topic in the official documentation and googling didn't bring me any further, any help and ideas would be appreciated very much.

推荐答案

哇!出于某种原因,研究小时后,我现在找到了pretty容易回答我的问题:我完全寻找在错误的地方,通过所有我能找到的 UICollectionView

Whoa! For some reason, after hours of research, I now found a pretty easy answer to my question: I was completely searching in the wrong place, digging through all the documentation I could find on UICollectionView.

简单和容易的解决方案在于基本的布局:只需拨打 collectionViewContentSize myCollectionView.collectionViewLayout 财产和你得到的高度和内容宽度 CGSize 。它就是这么简单。

The simple and easy solution lies in the underlying layout: Just call collectionViewContentSize on your myCollectionView.collectionViewLayout property and you get the height and width of the content as CGSize. It's as easy as that.

这篇关于如何确定UICollectionView高度具有FlowLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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