创建一个单元格高度大于视图高度的水平 UICollectionView
Create a horizontal UICollectionView with Cell's height larger than view's height
我用 UICollectionViewFlowLayout
和 UICollectionViewScrollDirectionHorizontal
创建了一个 UICollectionView
。我需要将视图的框架设置为固定高度。
但是,某些单元格的高度可能大于视图的高度。当显示此单元格时,控制台会抱怨:
the behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less than the height of the UICollectionView minus the section insets top and bottom values.
Please check the values return by the delegate.
我的布局设置如下:
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.minimumLineSpacing = 0.f;
layout.minimumInteritemSpacing = 0.f;
部分插入设置为 UIEdgeInsetsMake(0, 0, 0, 0)
。
UICollectionView
设置为固定帧,如CGRectMake(0,0,SCREEN_WIDTH, 100)
。
单元格的项目大小根据内容动态更改。所以有时它可以大于集合视图的高度(100)。
我该如何解决?
向 collectionCell 添加一个固定的 UIView(高度 < 100)。然后在这个固定的UIView上添加实际的视图(你想显示的)(根据内容动态改变)。
P/s: OP 也为这种控件找到了库 GMCPagingScrollView
。
我用 UICollectionViewFlowLayout
和 UICollectionViewScrollDirectionHorizontal
创建了一个 UICollectionView
。我需要将视图的框架设置为固定高度。
但是,某些单元格的高度可能大于视图的高度。当显示此单元格时,控制台会抱怨:
the behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less than the height of the UICollectionView minus the section insets top and bottom values.
Please check the values return by the delegate.
我的布局设置如下:
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.minimumLineSpacing = 0.f;
layout.minimumInteritemSpacing = 0.f;
部分插入设置为 UIEdgeInsetsMake(0, 0, 0, 0)
。
UICollectionView
设置为固定帧,如CGRectMake(0,0,SCREEN_WIDTH, 100)
。
单元格的项目大小根据内容动态更改。所以有时它可以大于集合视图的高度(100)。
我该如何解决?
向 collectionCell 添加一个固定的 UIView(高度 < 100)。然后在这个固定的UIView上添加实际的视图(你想显示的)(根据内容动态改变)。
P/s: OP 也为这种控件找到了库 GMCPagingScrollView
。