莫过于 UITableView 和 UICollectionView,随着应用越来越复杂,以前的 UICollectionViewFlowLayout 布局已经满足不了需求,而自定义布局又过于复杂,所以在 iOS 13 中 Apple 为 UICollectionView 推出了组合布局 UICollectionViewCompositionalLayout,这对于 UICollectionView 是一个全新的升级,它将赋予 UICollectionView 更多的...
另一方面 对于cell的样式和组织方式,由于collectionView比tableView要复杂得多,因此没有按照类似于tableView的style的方式来定义,而是专门使用了一个类来对collectionView的布局和行为进行描述,这就是UICollectionViewLayout 而我们主要讲UICollectionViewLayout,因为这不仅是collectionView和tableView的最重要求的区别,也是整个UIColl...
我们可以分析:因为UICollectionView是iOS6.0之前的新类,因此这里统一了从复用池中获取cell的方法,没有再提供可以返回nil的方式,并且在UICollectionView的回调代理中,只能使用从复用池中获取cell的方式进行cell的返回,其他方式会崩溃,例如: //这是正确的方法 -(UICollectionViewCell *)collectionView:(UICollectionView *)co...
1.当布局首次被加载时会调用prepareLayout函数 -(void)prepareLayout; 2.自定义ContentSize该方法会返回CollectionView的大小,这个方法也是自定义布局中必须实现的方法 -(CGSize)collectionViewContentSize; 3.该方法返回一个数组,该数组中存放的是为每个Cell绑定的UICollectionViewLayoutAttributes属性 -(NSArray *)layoutAttr...
classStackedLayout:UICollectionViewLayout{varcache:[UICollectionViewLayoutAttributes]=[]varcontentSize:CGSize=.zerooverridefuncprepare(){// 清空缓存cache.removeAll()vartotalHeight:CGFloat=0letitemWidth=collectionView!.bounds.width*0.8// Cell 宽度foriin0..<collectionView!.numberOfItems(inSection:0){letind...
3.下面的方法是为每个Cell去绑定一个UICollectionViewLayoutAttributes对象,并且以数组的形式返回,在我们的自定义瀑布流中,我们只自定义了Cell的frame,就可以实现我们的瀑布流,UICollectionViewLayoutAttributes的其他属性我们没有用到,由此可以看出自定义Cell布局功能的强大。
UICollectionViewCompositionalLayout 是在已有的 Item 和 Section 的基础上,增加了一个 Group 的概念。多个 Item 组成一个 Group ,多个 Group 组成一个 Section,层级关系变为: Item -> Group -> Section -> Layout 。决定了一个元素的大小。表达一个元素的 Size 有三种方法:描述一个 Item 的...
当我们要实现App store的游戏页面的时候,惯性思维可能就是我们需要建立一个UITableView,并且在tableHeaderView或者在第一个cell内部嵌套一个横向滑动的UICollectionView。\ 其实我们可以直接用一个collectionView就可以实现这么一个效果。这就是今天的主角——UICollectionViewCompositionalLayout。
Note: that this library is still currently under active development. Please file all bugs, issues, and suggestions as an Issue in the GitHub repository. What is Collection View Compositional Layouts? At the WWDC 2019, Apple introduced a new form of UICollectionViewLayout. A new UICollectionViewCo...
https://github.com/OneWang/Header-Footer-FlowLayout这个带有头尾视图的瀑布流实现 https://github.com/OneWang/Layout这个是 UICollectionView 的其它形式的布局的实现 UICollectionView相对于UITableView很相似,但它的功能要更加强大,并且其基本用法和 UITableView 的一样的,在这里基本的属性和代理方法就不一一介绍了...