简体   繁体   English

集合视图组合布局 - 动态布局

[英]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框架中实现的功能来根据以前未知的单元格大小创建布局。

My problem:我的问题:

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.

相关问题 具有估计高度的集合视图组合布局不起作用 - Collection View Compositional Layout with estimated height not working 组合布局中的集合视图自调整单元格问题 - Collection view self-sizing cells issue in Compositional layout 如何在 iOS 上隐藏 header 13 集合视图组合布局 - How hide header on iOS 13 Collection View Compositional Layout 如何防止自动聚焦在集合视图组合布局 swift - How to prevent auto focus on collection view compositional layout swift 集合视图单元格组合布局之间不需要的空间 - Unwanted space between Collection View cells Compositional Layout "如何使用集合视图组合布局使集合视图内的单元格居中" - How to center cells inside collection view using collection view compositional layout 我认为集合视图拖放+组合布局不能一起工作是否正确? - Am I correct in thinking collection view drag and drop + compositional layout just don't work together? 如何使用这样的图像/图标/视图偏移组合布局 - How can I offset a Compositional Layout with an image / icon / view like this 如何在具有组合布局的新集合视图中将 CAGradientLayer 添加到 UIBackgroundConfiguration ? - How do you add a CAGradientLayer to a UIBackgroundConfiguration in the new collection views with compositional layouts? 在“收藏夹视图”中垂直和水平滚动-嵌入式流程布局与自定义布局 - Scrolling vertically and horizontally in Collection View - embedded flow layouts vs custom layout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM