[英]Collection View Compositional Layouts - Layout on the fly
After seeing the wonderful Advances in Collection View Layout Session , I wondered if is possible to use the capabilities implemented in the new Collection View Compositional Layouts
framework to create a layout based on previously unknown cell sizes.在看到了Collection View Layout Session 中的精彩进展之后,我想知道是否可以使用新的Collection View Compositional Layouts
框架中实现的功能来根据以前未知的单元格大小创建布局。
Imagine a horizontal image gallery with two levels, the photos can be "vertical" or "horizontal", and the app is fetching them when are needed for display, and they are provided randomly ("horizontally" or "vertically").想象一个有两个层次的水平图片库,照片可以是“垂直”或“水平”,应用程序在需要显示时获取它们,它们是随机提供的(“水平”或“垂直”)。 So we have to populate the gallery with a "random pattern" (Pinterest style, here is how to do it with UICollectionViewFlowLayout
).所以我们必须用“随机模式”填充图库(Pinterest 风格, 这里是如何使用UICollectionViewFlowLayout
做到这UICollectionViewFlowLayout
)。
I cannot see a "group" pattern to populate the cells, because the layout has infinite possibilities, vertical divisions can appear to create groups, but also can not.我看不到填充单元格的“组”模式,因为布局具有无限的可能性,垂直分区可以出现以创建组,但也不能。
Is it possible to archive with Collection View Compositional Layouts
?是否可以使用Collection View Compositional Layouts
存档?
Thank you.谢谢你。
When you're setting your item layout size, you can use an estimated
layout dimension to make the size dependent on its contents.当您设置项目布局大小时,您可以使用estimated
布局尺寸使大小取决于其内容。 So an image view can set the cell size from the inside out using constraints.因此,图像视图可以使用约束从内向外设置单元格大小。 You size the image when you populate the cell, depending on whether it is horizontal or vertical, and the image view adopts the size of the image and the cell adopts the size of the image view.在填充单元格时调整图像的大小,取决于它是水平还是垂直,图像视图采用图像的大小,单元格采用图像视图的大小。
(If you needed even more control you could construct your group as a NSCollectionLayoutGroup.custom
, which allows you set every item's frame manually. But there's no need for such extremes in this simple situation, and besides, that assumes you know the frame at layout declaration time, which you probably don't.) (如果您需要更多控制,您可以将您的组构造为NSCollectionLayoutGroup.custom
,这允许您手动设置每个项目的框架。但在这种简单情况下不需要这种极端情况,此外,假设您知道布局中的框架声明时间,你可能没有。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.