为 UICollectionView 设置最小内容大小 [英] Set minimum contentsize for UICollectionView
问题描述
我希望能够在 UICollectionView 中设置内容大小的最小高度,以便我可以隐藏/显示 UISearchbar,类似于在 iBooks 上完成的方式.
I want to be able to set the minimum height of the content size within a UICollectionView, so I can hide/show a UISearchbar, similar to the way it's done on iBooks.
但是,我不想对布局进行子类化,因为我想保留 UICollectionView 的标准垂直布局.
However, I don't want to subclass the layout as I want to keep the standard vertical layout for a UICollectionView.
有什么想法吗?
推荐答案
你可以通过继承 UICollectionViewFlowLayout 并覆盖方法来做到这一点
You can do this by subclassing UICollectionViewFlowLayout and overriding the method
-(CGSize)collectionViewContentSize
{ //Get the collectionViewContentSize
CGSize size = [super collectionViewContentSize];
if (size < minimumSize) return minimumSize;
else return size;
}
我刚刚意识到你说你不想对布局进行子类化.无论如何,我继承了 UICollectionViewFlowLayout 并且只修改了 collectionViewContentSize 方法.它为我保留了标准的垂直布局.
I just realized you said you didn't want to subclass the layout. Anyway, I subclassed UICollectionViewFlowLayout and only modified the collectionViewContentSize method. It kept the standard vertical layout for me.
https://stackoverflow.com/a/14465485/2017159.这里说UICollectionViewFlowLayout只支持一个方向(垂直或者水平),应该没问题吧?
https://stackoverflow.com/a/14465485/2017159. Here it says UICollectionViewFlowLayout only supports one direction (vertical or horizontal), so it should be fine?
这篇关于为 UICollectionView 设置最小内容大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!