简体   繁体   English

馆藏视图布局问题

[英]Collection View Layout Issue

I have used collection view to create the following layout: 我已使用集合视图创建以下布局:

在此处输入图片说明

I have set the size of the layout using sizeForItemAtIndexPath method of collection view and using flow layout but what I could achieve is: 我已经使用集合视图的sizeForItemAtIndexPath方法并使用流布局来设置布局的大小,但是我可以实现的是:

在此处输入图片说明

I tried reducing the width and height but even then I cannot achieve the two elements below each other. 我尝试减小宽度和高度,但即使如此,我也无法实现彼此之间的两个元素。

Creating a layout that behaves like you first picture is simply not possible without writing a custom subclass of UICollectionViewLayout (as rdelmar mentioned in the comment). 如果不编写UICollectionViewLayout的自定义子类(如注释中提到的rdelmar),就无法创建行为就像您的第一张图片一样。 But I have recently experienced a similar problem as you. 但是我最近遇到了与您类似的问题。 For me this github project was very helpful: https://github.com/chiahsien/CHTCollectionViewWaterfallLayout 对我来说,这个github项目非常有帮助: https : //github.com/chiahsien/CHTCollectionViewWaterfallLayout

It looks like you can also use this layout for you CollectionView. 看起来您也可以为CollectionView使用此布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM