OC CollectionView笔记

2016-12-12  本文已影响153人  cry_0416

自定义layout


- (void)prepareLayout{

    [super prepareLayout];
    
    ///布局,计算出每个item的frame
    //保存进attrs数组
}
- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect{

    return _attrs;//返回每个item的布局,数组
}

- (CGSize)collectionViewContentSize{
 
    NSArray *tempArray = [_infos sortedArrayUsingSelector:@selector(compare:)];
    NSNumber *maxNum = tempArray.lastObject;
    return CGSizeMake(self.collectionView.bounds.size.width, maxNum.floatValue);//
}

上拉加载/无缝请求

- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
    
    //在这个回调里面判断,是否达到请求数据的界
    //而且要判断滑的方向
    //请求不能重复
}

自定义Cell

上一篇 下一篇

猜你喜欢

热点阅读