自定义UICollectionViewFlowLayout

//1.实现
-(void)prepareLayout{
    //(目的:做一些初始化;用来做布局的初始化操作(不建议在init方法里面做布局的初始化操作))
}
 
//2.实现
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect{
    //(目的:拿出它计算好的布局属性来做一个微调,实现cell不断变大变小)
        NSArray *array =[super layoutAttributesForElementsInRect:rect] ;
        for (UICollectionViewLayoutAttributes *attrs in array) {
             //更改attrs就可以更改frame,bounds等属性
        }
        return array;
}
 
//3.实现
- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity{
    //(目的:当我们手一松开,它最终停止滚动的时候,应该去在哪.它决定了collectionView停止滚动时候的偏移量)
}
 
//4.实现
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds{
    //(只要滑动就会重新刷新,就会调用prepareLayout和layoutAttributesForElementsInRect方法)
}
原文地址:https://www.cnblogs.com/cfl911014/p/7325676.html