问题标签 [uicollectionviewflowlayout]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
1110 浏览

ios - UICollectionView“流向”

UICollectionView 的典型流程是“移动,然后向下”

在此处输入图像描述

我很好奇是否有办法颠倒“流”的顺序,即“先向下”(最大行数,然后穿过。)类似于这样:

在此处输入图像描述

0 投票
0 回答
52 浏览

swift - 如何为 CollectionView Cell 指定行数、列数和间距

我想指定集合视图单元格项目之间的行数、列数以及空间,然后我希望我的单元格的宽度和高度应由 ios 确定。怎么做 ?请检查我的以下代码脚本。当我更改行数和列数时,有时我看不到单元格之间的相等空间。如何看到总是相等的空间,并且还想要行和列。

0 投票
1 回答
395 浏览

ios - Swift4 - 我第一次无法显示 CollectionView “无法同时满足约束”

我正在使用 Swift 4 创建一个应用程序,我在其中向 API 发出请求,并且我想在 CollectionView 上返回结果。

但我收到以下错误,我认为这是来自约束:

在此处输入图像描述

此块重复 100 次。

结果是他没有画任何细胞。显示这样的图像:

在此处输入图像描述

除非我按两次顶部按钮“更改自动布局”。当您绘制您拥有的两种显示模式的单元格时,它看起来像这样:

在此处输入图像描述

和这个:

在此处输入图像描述

但问题是,最初什么都没有显示,应该显示。并且出现了我在开始时向您展示的错误。

为了对您有所帮助,因为我会说问题源于应用的约束,所以我附上了一些应用了不同约束的图像。

collectionView 所在的初始 xib 是:

在此处输入图像描述

最初加载的单元格是:

在此处输入图像描述

我们更改布局后的单元格是这样的:

在此处输入图像描述

我附上了控制 CollectionView 的主类 ViewVontroller 的代码:

事实是,我不知道为什么会发生布局冲突。但这让我发疯......我无法理解最初未显示单元格的方式(因为正在接收数据)。会是什么呢?

非常感谢,有什么问题请附上我。

[代码更新]

这些是代码解决方案:

0 投票
1 回答
289 浏览

swift - 重新加载时 UICollectionViewCell 错误的高度

我将这个问题作为这个问题的一个分支

ViewCells 上的自动调整大小非常完美。但是当我重新加载我的 CollectionView 时,高度返回 1。

代码如下。

缺少什么或我应该重新考虑什么来保持我的自动高度?

提前致谢。

0 投票
2 回答
2990 浏览

swift - UICollectionView 根据内容动态单元格高度 | Pinterest 布局

我正在尝试按照 Pinterest 用于他们的图片库的布局进行布局。但问题是我将图像高度返回到单元格的大小,当图像具有不同的高度时,它会在单元格中留下空间。

我浏览了很多文章,但我没有找到一个简单的解决方案。有什么简单的方法可以做到这一点吗?

请看这张图片

0 投票
1 回答
679 浏览

ios - UICollectionView Cell Custom FlowLayout Breaks When New Post is Added on Top

Description: I have been working on an app which displays images and caption in a CollectionView. I have made a custom Cell and CustomFlowLayout for the cell where the width of the cell, image and caption is equal to width of screen and height will change according to aspect ratio of the image height and height needed for the caption. The images which are displayed are stored on FirebaseStorage and I have also saved imagewidth and imageheight in firebaseDatabase. I Use SD_Web images to load and cache images. When the app loads for the first time the layout works perfectly fine as expected. The cells are arranged according to image height and caption height , with images being in aspect ratio. The main problem occurs when a new post is done. I insert new post on the top of collectionview, and when the post is received the layout breaks, images becomes messed up, the caption goes on top image, lot of white space between image or caption. when I terminate the app from background and run it again , this time the layout is perfectly fine with new post present. I have to terminate app after everyone post to make the layout work.

What I feel the problem is, when I post the image. The new post is added on the top cell and the item on top cell pushed below without having the old height. how can I take this problem. I tried searching a lot but still of no use. PS: Using Autolayout for cell in IB.

FactsFeverLayout Class

CollectionViewCell Class

ViewController Class

0 投票
1 回答
1889 浏览

ios - 自动调整集合视图单元格大小会忽略首次显示时的自动布局

情况

我用 UICollectionViewFlowLayout.automaticSize 做了一个水平滚动的集合视图。集合视图的高度为 40 单元格的高度为 40,这是我在初始化时通过 autolayou 设置的。

问题

问题是只有在第一次显示集合视图时显示的单元格的大小为 50x50,它覆盖了自动布局高度 40,我通过代码手动设置。

我检查了 willDisplayCell 委托方法的大小。

当我滚动集合视图以显示其他单元格时,每个新显示的单元格都有适当的大小,高度为 40。

尽管尺寸为 50x50(如记录)的单元格在屏幕上正确显示(高度似乎为 40)。

由此,当我在模拟器上运行应用程序时收到错误消息(记录),如果我在我的真实设备(iPhone8 iOS 11)上运行应用程序崩溃。

代码

视图控制器

细胞

0 投票
1 回答
262 浏览

swift - UICollectionView 不同大小的单元格和项目数

使用UICollectionView流委托,我正在尝试完成此操作,但我仍然需要删除两个单元格区域中的巨大间距。

在此处输入图像描述

我的代码:

预期的 :

在此处输入图像描述

0 投票
2 回答
1324 浏览

ios - 更改 UICollectionView 单元格 X 位置 - 快速

如何以编程方式更改每个单元格的 X 位置?我可以根据自己的意愿更改单元格的宽度和高度,但由于 XY 位置,它无法完成项目。

  • 我的结果

    在此处输入图像描述

  • 预期结果是,

在此处输入图像描述

我的全视图控制器代码是,

任何人都请帮我找出解决方案。谢谢...

0 投票
0 回答
51 浏览

ios - 具有自动调整单元大小的集合视图在重新加载后停止工作

在我的应用程序中,我有一个集合视图,其中单元格水平自动调整大小。这是一些代码:

该单元格有 1 个视图,该视图具有高度约束。此视图子视图一个标签,该标签限制为 2 行,不受宽度限制。这里的想法是允许标签在 2 行中计算自己的宽度适合文本。

为了完成这项工作,我在单元类中添加了以下代码:

现在,它完美运行。单元格是 autosizng,scrollView 是水平滚动等。直到我reloadData()至少调用一次。然后单元格的大小为 50x50,并且在我离开屏幕并再次返回之前不再自动调整大小。

你有什么想法为什么会发生?