collectionView实现瀑布流效果,只需要重写layout即可。
设置代理(根据宽度计算出cell高度) 不在layout中计算,而是在代理中计算,是为了保证cell上得图片不变形
@class WTKWaterFlowLayout;
@protocol WTKWaterFlowLayoutDelegate <NSObject>
- (CGFloat)waterFlowLayout:(WTKWaterFlowLayout *)waterFlowLayout cellWidth:(CGFloat)width atIndexPath:(NSIndexPath *)indexPaht;
@end
@interface WTKWaterFlowLayout : UICollectionViewLayout
重写layout的几个方法
1、
- (void)prepareLayout
{
for (int i = 0; i<3; i++)
{
NSString *key = [NSString stringWithFormat:@"%d",i];
self.maxDic[key] = @0;