自定義layout
- (void)prepareLayout{
[super prepareLayout];
///布局,計算出每個item的frame
//保存進(jìn)attrs數(shù)組
}
- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect{
return _attrs;//返回每個item的布局,數(shù)組
}
- (CGSize)collectionViewContentSize{
NSArray *tempArray = [_infos sortedArrayUsingSelector:@selector(compare:)];
NSNumber *maxNum = tempArray.lastObject;
return CGSizeMake(self.collectionView.bounds.size.width, maxNum.floatValue);//
}
- 算出有多少列
- 根據(jù)寬,indexPath計算x,y
- 保存最大的y值,返回collection的contentSize
上拉加載/無縫請求
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
//在這個回調(diào)里面判斷,是否達(dá)到請求數(shù)據(jù)的界
//而且要判斷滑的方向
//請求不能重復(fù)
}
自定義Cell
在
- (instancetype)initWithFrame:(CGRect)frame
方法里自定義在
- (void)layoutSubviews
里才能獲取到frame