天天省钱快报

WSLWaterFlowLayout.m 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. //
  2. // WSLWaterFlowLayout.m
  3. // collectionView
  4. //
  5. // Created by 王双龙 on 2017/10/16.
  6. // Copyright © 2017年 https://www.jianshu.com/u/e15d1f644bea All rights reserved.
  7. //
  8. #import "WSLWaterFlowLayout.h"
  9. /** 默认的列数*/
  10. static const NSInteger WSLDefaultColumeCount = 2;
  11. /** 默认的行数*/
  12. static const NSInteger WSLDefaultRowCount = 5;
  13. /** 每一列之间的间距*/
  14. static const NSInteger WSLDefaultColumeMargin = 10;
  15. /** 每一行之间的间距*/
  16. static const CGFloat WSLDefaultRowMargin = 10;
  17. /** 边缘之间的间距*/
  18. static const UIEdgeInsets WSLDefaultEdgeInset = {10, 10, 10, 10};
  19. ///** 每一行之间的间距*/
  20. //static const CGSize WSLDefaultHeaderSize = CGSizeMake(0, 66);
  21. ///** 每一行之间的间距*/
  22. //static const CGSize WSLDefaultFooterSize = CGSizeMake(0, 66);
  23. @interface WSLWaterFlowLayout ()
  24. /** 存放所有cell的布局属性*/
  25. @property (strong, nonatomic) NSMutableArray *attrsArray;
  26. /** 存放每一列的最大y值*/
  27. @property (nonatomic, strong) NSMutableArray *columnHeights;
  28. /** 存放每一行的最大x值*/
  29. @property (nonatomic, strong) NSMutableArray *rowWidths;
  30. /** 内容的高度*/
  31. @property (nonatomic, assign) CGFloat maxColumnHeight;
  32. /** 内容的宽度*/
  33. @property (nonatomic, assign) CGFloat maxRowWidth;
  34. /** 列数*/
  35. -(NSInteger)columnCount;
  36. /** 行数*/
  37. -(NSInteger)rowCount;
  38. /** 每一行之间的间距*/
  39. -(CGFloat)rowMargin;
  40. /** 每一列之间的间距*/
  41. -(CGFloat)columnMargin;
  42. /** 边缘之间的间距*/
  43. -(UIEdgeInsets)edgeInsets;
  44. @end
  45. @implementation WSLWaterFlowLayout
  46. #pragma mark item属性配置
  47. -(CGFloat)columnMargin {
  48. if ([self.delegate respondsToSelector:@selector(columnMarginInWaterFlowLayout:)]) {
  49. return [self.delegate columnMarginInWaterFlowLayout:self];
  50. } else {
  51. return WSLDefaultColumeMargin;
  52. }
  53. }
  54. -(CGFloat)rowMargin {
  55. if ([self.delegate respondsToSelector:@selector(rowMarginInWaterFlowLayout:)]) {
  56. return [self.delegate rowMarginInWaterFlowLayout:self];
  57. } else {
  58. return WSLDefaultRowMargin;
  59. }
  60. }
  61. -(NSInteger)columnCount {
  62. if ([self.delegate respondsToSelector:@selector(columnCountInWaterFlowLayout:)]) {
  63. return [self.delegate columnCountInWaterFlowLayout:self];
  64. } else {
  65. return WSLDefaultColumeCount;
  66. }
  67. }
  68. -(NSInteger)rowCount{
  69. if ([self.delegate respondsToSelector:@selector(rowCountInWaterFlowLayout:)]) {
  70. return [self.delegate rowCountInWaterFlowLayout:self];
  71. } else {
  72. return WSLDefaultRowCount;
  73. }
  74. }
  75. -(UIEdgeInsets)edgeInsets {
  76. if ([self.delegate respondsToSelector:@selector(edgeInsetInWaterFlowLayout:)]) {
  77. return [self.delegate edgeInsetInWaterFlowLayout:self];
  78. } else {
  79. return WSLDefaultEdgeInset;
  80. }
  81. }
  82. #pragma mark - 懒加载
  83. - (NSMutableArray *)columnHeights {
  84. if (!_columnHeights) {
  85. _columnHeights = [NSMutableArray array];
  86. }
  87. return _columnHeights;
  88. }
  89. - (NSMutableArray *)rowWidths {
  90. if (!_rowWidths) {
  91. _rowWidths = [NSMutableArray array];
  92. }
  93. return _rowWidths;
  94. }
  95. -(NSMutableArray *)attrsArray {
  96. if (_attrsArray == nil) {
  97. _attrsArray = [NSMutableArray array];
  98. }
  99. return _attrsArray;
  100. }
  101. #pragma mark - 重写系统方法
  102. /** 初始化 生成每个视图的布局信息*/
  103. -(void)prepareLayout {
  104. [super prepareLayout];
  105. if (self.flowLayoutStyle == WSLVerticalWaterFlow) {
  106. //清除以前计算的所有高度
  107. self.maxColumnHeight = 0;
  108. [self.columnHeights removeAllObjects];
  109. for (NSInteger i = 0; i < self.columnCount; i++) {
  110. [self.columnHeights addObject:@(self.edgeInsets.top)];
  111. }
  112. }else if (self.flowLayoutStyle == WSLHorizontalWaterFlow){
  113. //清除以前计算的所有宽度
  114. self.maxRowWidth = 0;
  115. [self.rowWidths removeAllObjects];
  116. for (NSInteger i = 0; i < self.rowCount; i++) {
  117. [self.rowWidths addObject:@(self.edgeInsets.left)];
  118. }
  119. }else if (self.flowLayoutStyle == WSLVHWaterFlow || self.flowLayoutStyle == WSLLineWaterFlow){
  120. //记录最后一个的内容的横坐标和纵坐标
  121. self.maxColumnHeight = 0;
  122. [self.columnHeights removeAllObjects];
  123. [self.columnHeights addObject:@(self.edgeInsets.top)];
  124. self.maxRowWidth = 0;
  125. [self.rowWidths removeAllObjects];
  126. [self.rowWidths addObject:@(self.edgeInsets.left)];
  127. }
  128. //清除之前数组
  129. [self.attrsArray removeAllObjects];
  130. //开始创建每一组cell的布局属性
  131. NSInteger sectionCount = [self.collectionView numberOfSections];
  132. for(NSInteger section = 0; section < sectionCount; section++){
  133. //获取每一组头视图header的UICollectionViewLayoutAttributes
  134. if([self.delegate respondsToSelector:@selector(waterFlowLayout:sizeForHeaderViewInSection:)]){
  135. UICollectionViewLayoutAttributes *headerAttrs = [self layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:section]];
  136. [self.attrsArray addObject:headerAttrs];
  137. }
  138. //开始创建组内的每一个cell的布局属性
  139. NSInteger rowCount = [self.collectionView numberOfItemsInSection:section];
  140. for (NSInteger row = 0; row < rowCount; row++) {
  141. //创建位置
  142. NSIndexPath *indexPath = [NSIndexPath indexPathForItem:row inSection:section];
  143. //获取indexPath位置cell对应的布局属性
  144. UICollectionViewLayoutAttributes *attrs = [self layoutAttributesForItemAtIndexPath:indexPath];
  145. [self.attrsArray addObject:attrs];
  146. }
  147. //获取每一组脚视图footer的UICollectionViewLayoutAttributes
  148. if([self.delegate respondsToSelector:@selector(waterFlowLayout:sizeForFooterViewInSection:)]){
  149. UICollectionViewLayoutAttributes *footerAttrs = [self layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionFooter atIndexPath:[NSIndexPath indexPathForItem:0 inSection:section]];
  150. [self.attrsArray addObject:footerAttrs];
  151. }
  152. }
  153. }
  154. /** 决定一段区域所有cell和头尾视图的布局属性*/
  155. -(NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect {
  156. return self.attrsArray;
  157. }
  158. /** 返回indexPath位置cell对应的布局属性*/
  159. -(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
  160. //设置布局属性
  161. UICollectionViewLayoutAttributes *attrs = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
  162. if (self.flowLayoutStyle == WSLVerticalWaterFlow) {
  163. attrs.frame = [self itemFrameOfVerticalWaterFlow:indexPath];
  164. }else if (self.flowLayoutStyle == WSLHorizontalWaterFlow){
  165. attrs.frame = [self itemFrameOfHorizontalWaterFlow:indexPath];
  166. }else if(self.flowLayoutStyle == WSLVHWaterFlow){
  167. attrs.frame = [self itemFrameOfVHWaterFlow:indexPath];
  168. }else if(self.flowLayoutStyle == WSLLineWaterFlow){
  169. attrs.frame = [self itemFrameOfLineWaterFlow:indexPath];
  170. // 计算中心点距离
  171. CGFloat delta = fabs((attrs.center.x - self.collectionView.contentOffset.x) - self.collectionView.frame.size.width * 0.5);
  172. //计算比例
  173. CGFloat scale = 1 - delta / (self.collectionView.frame.size.width * 0.5) * 0.25;
  174. attrs.transform = CGAffineTransformMakeScale(scale, scale);
  175. }
  176. return attrs;
  177. }
  178. /** 返回indexPath位置头和脚视图对应的布局属性*/
  179. - (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath{
  180. UICollectionViewLayoutAttributes *attri;
  181. if ([UICollectionElementKindSectionHeader isEqualToString:elementKind]) {
  182. //头视图
  183. attri = [UICollectionViewLayoutAttributes layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionHeader withIndexPath:indexPath];
  184. attri.frame = [self headerViewFrameOfVerticalWaterFlow:indexPath];
  185. }else {
  186. //脚视图
  187. attri = [UICollectionViewLayoutAttributes layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionFooter withIndexPath:indexPath];
  188. attri.frame = [self footerViewFrameOfVerticalWaterFlow:indexPath];
  189. }
  190. return attri;
  191. }
  192. /** 返回值决定了collectionView停止滚动时的偏移量 手指松开后执行
  193. * proposedContentOffset:原本情况下,collectionView停止滚动时最终的偏移量
  194. * velocity 滚动速率,通过这个参数可以了解滚动的方向
  195. */
  196. /*
  197. - (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity
  198. {
  199. if (self.flowLayoutStyle == WSLLineWaterFlow) {
  200. // 拖动比较快 最终偏移量 不等于 手指离开时偏移量
  201. CGFloat collectionW = self.collectionView.frame.size.width;
  202. // 最终偏移量
  203. CGPoint targetP = [super targetContentOffsetForProposedContentOffset:proposedContentOffset withScrollingVelocity:velocity];
  204. // 0.获取最终显示的区域
  205. CGRect targetRect = CGRectMake(targetP.x, 0, collectionW, MAXFLOAT);
  206. // 1.获取最终显示的cell
  207. NSArray *attrs = [super layoutAttributesForElementsInRect:targetRect];
  208. // 获取最小间距
  209. CGFloat minDelta = MAXFLOAT;
  210. for (UICollectionViewLayoutAttributes *attr in attrs) {
  211. // 获取距离中心点距离:注意:应该用最终的x
  212. CGFloat delta = (attr.center.x - targetP.x) - self.collectionView.bounds.size.width * 0.5;
  213. if (fabs(delta) < fabs(minDelta)) {
  214. minDelta = delta;
  215. }
  216. }
  217. // 移动间距
  218. targetP.x += minDelta;
  219. if (targetP.x < 0) {
  220. targetP.x = 0;
  221. }
  222. return targetP;
  223. }
  224. return proposedContentOffset;
  225. }
  226. // Invalidate:刷新
  227. // 在滚动的时候是否允许刷新布局
  228. - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds{
  229. if (self.flowLayoutStyle == WSLLineWaterFlow) {
  230. return YES;
  231. }
  232. return NO;
  233. }
  234. */
  235. //返回内容高度
  236. -(CGSize)collectionViewContentSize {
  237. if (self.flowLayoutStyle == WSLVerticalWaterFlow) {
  238. return CGSizeMake(0, self.maxColumnHeight + self.edgeInsets.bottom);
  239. }else if (self.flowLayoutStyle == WSLHorizontalWaterFlow){
  240. return CGSizeMake(self.maxRowWidth + self.edgeInsets.right, 0);
  241. }else if(self.flowLayoutStyle == WSLVHWaterFlow){
  242. return CGSizeMake(0 , self.maxColumnHeight + self.edgeInsets.bottom);
  243. }else if(self.flowLayoutStyle == WSLLineWaterFlow){
  244. return CGSizeMake(self.maxRowWidth + self.edgeInsets.right , 0);;
  245. }
  246. return CGSizeMake(0, 0);
  247. }
  248. #pragma mark - Help Methods
  249. //竖向瀑布流 item等宽不等高
  250. - (CGRect)itemFrameOfVerticalWaterFlow:(NSIndexPath *)indexPath{
  251. //collectionView的宽度
  252. CGFloat collectionW = self.collectionView.frame.size.width;
  253. //设置布局属性item的frame
  254. CGFloat w = (collectionW - self.edgeInsets.left - self.edgeInsets.right - (self.columnCount - 1) * self.columnMargin) / self.columnCount;
  255. CGFloat h = [self.delegate waterFlowLayout:self heightForItemAtIndexPath:indexPath itemWidth:w];
  256. //找出高度最短的那一列
  257. NSInteger destColumn = 0;
  258. CGFloat minColumnHeight = [self.columnHeights[0] doubleValue];
  259. for (NSInteger i = 1; i < self.columnCount; i++) {
  260. //取出第i列
  261. CGFloat columnHeight = [self.columnHeights[i] doubleValue];
  262. if (minColumnHeight > columnHeight) {
  263. minColumnHeight = columnHeight;
  264. destColumn = i;
  265. }
  266. }
  267. CGFloat x = self.edgeInsets.left + destColumn * (w + self.columnMargin);
  268. CGFloat y = minColumnHeight;
  269. if (y != self.edgeInsets.top) {
  270. y += self.rowMargin;
  271. }
  272. //更新最短那列的高度
  273. self.columnHeights[destColumn] = @(CGRectGetMaxY(CGRectMake(x, y, w, h)));
  274. //记录内容的高度
  275. CGFloat columnHeight = [self.columnHeights[destColumn] doubleValue];
  276. if (self.maxColumnHeight < columnHeight) {
  277. self.maxColumnHeight = columnHeight;
  278. }
  279. return CGRectMake(x, y, w, h);
  280. }
  281. //竖向瀑布流 item等高不等宽
  282. - (CGRect)itemFrameOfVHWaterFlow:(NSIndexPath *)indexPath{
  283. //collectionView的宽度
  284. CGFloat collectionW = self.collectionView.frame.size.width;
  285. CGSize headViewSize = CGSizeMake(0, 0);
  286. if([self.delegate respondsToSelector:@selector(waterFlowLayout:sizeForHeaderViewInSection:)]){
  287. headViewSize = [self.delegate waterFlowLayout:self sizeForHeaderViewInSection:indexPath.section];
  288. }
  289. CGFloat w = [self.delegate waterFlowLayout:self sizeForItemAtIndexPath:indexPath].width;
  290. CGFloat h = [self.delegate waterFlowLayout:self sizeForItemAtIndexPath:indexPath].height;
  291. CGFloat x;
  292. CGFloat y;
  293. //记录最后一行的内容的横坐标和纵坐标
  294. if (collectionW - [[self.rowWidths firstObject] floatValue] > w + self.edgeInsets.right) {
  295. x = [[self.rowWidths firstObject] floatValue] == self.edgeInsets.left ? self.edgeInsets.left : [[self.rowWidths firstObject] floatValue] + self.columnMargin;
  296. if ([[self.columnHeights firstObject] floatValue] == self.edgeInsets.top) {
  297. y = self.edgeInsets.top;
  298. }else if ([[self.columnHeights firstObject] floatValue] == self.edgeInsets.top + headViewSize.height) {
  299. y = self.edgeInsets.top + headViewSize.height + self.rowMargin;
  300. }else{
  301. y = [[self.columnHeights firstObject] floatValue] - h;
  302. }
  303. [self.rowWidths replaceObjectAtIndex:0 withObject:@(x + w )];
  304. if ([[self.columnHeights firstObject] floatValue] == self.edgeInsets.top || [[self.columnHeights firstObject] floatValue] == self.edgeInsets.top + headViewSize.height) {
  305. [self.columnHeights replaceObjectAtIndex:0 withObject:@(y + h)];
  306. }
  307. }else if(collectionW - [[self.rowWidths firstObject] floatValue] == w + self.edgeInsets.right){
  308. //换行
  309. x = self.edgeInsets.left;
  310. y = [[self.columnHeights firstObject] floatValue] + self.rowMargin;
  311. [self.rowWidths replaceObjectAtIndex:0 withObject:@(x + w)];
  312. [self.columnHeights replaceObjectAtIndex:0 withObject:@(y + h)];
  313. }else{
  314. //换行
  315. x = self.edgeInsets.left;
  316. y = [[self.columnHeights firstObject] floatValue] + self.rowMargin;
  317. [self.rowWidths replaceObjectAtIndex:0 withObject:@(x + w)];
  318. [self.columnHeights replaceObjectAtIndex:0 withObject:@(y + h)];
  319. }
  320. //记录内容的高度
  321. self.maxColumnHeight = [[self.columnHeights firstObject] floatValue] ;
  322. return CGRectMake(x, y, w, h);
  323. }
  324. //水平瀑布流 item等高不等宽
  325. - (CGRect)itemFrameOfHorizontalWaterFlow:(NSIndexPath *)indexPath{
  326. //collectionView的高度
  327. CGFloat collectionH = self.collectionView.frame.size.height;
  328. //设置布局属性item的frame
  329. CGFloat h = (collectionH - self.edgeInsets.top - self.edgeInsets.bottom - (self.rowCount - 1) * self.rowMargin) / self.rowCount;
  330. CGFloat w = [self.delegate waterFlowLayout:self widthForItemAtIndexPath:indexPath itemHeight:h];
  331. //找出宽度最短的那一行
  332. NSInteger destRow = 0;
  333. CGFloat minRowWidth = [self.rowWidths[0] doubleValue];
  334. for (NSInteger i = 1; i < self.rowWidths.count; i++) {
  335. //取出第i行
  336. // CGFloat rowWidth = [self.rowWidths[i] doubleValue];
  337. // if (minRowWidth > rowWidth) {
  338. // minRowWidth = rowWidth;
  339. // destRow = i;
  340. // }
  341. }
  342. CGFloat y = self.edgeInsets.top + indexPath.section * (h + self.rowMargin);
  343. CGFloat x = minRowWidth;
  344. if (indexPath.item == 0) {
  345. x = self.edgeInsets.left;
  346. }
  347. if (x != self.edgeInsets.left) {
  348. x += self.columnMargin;
  349. }
  350. //更新最短那行的宽度
  351. self.rowWidths[destRow] = @(CGRectGetMaxX(CGRectMake(x, y, w, h)));
  352. //记录内容的宽度
  353. CGFloat rowWidth = [self.rowWidths[destRow] doubleValue];
  354. if (self.maxRowWidth < rowWidth) {
  355. self.maxRowWidth = rowWidth ;
  356. }
  357. NSLog(@"%ld-%ld",indexPath.section,indexPath.item);
  358. NSLog(@"%@",NSStringFromCGRect(CGRectMake(x, y, w, h)));
  359. return CGRectMake(x, y, w, h);
  360. }
  361. - (CGRect)itemFrameOfLineWaterFlow:(NSIndexPath *)indexPath{
  362. //collectionView的高度
  363. CGFloat collectionH = self.collectionView.frame.size.height;
  364. //设置布局属性item的frame
  365. CGFloat h = [self.delegate waterFlowLayout:self sizeForItemAtIndexPath:indexPath].height;
  366. CGFloat w = [self.delegate waterFlowLayout:self sizeForItemAtIndexPath:indexPath].width;
  367. CGFloat y = self.edgeInsets.top;
  368. CGFloat x = [[self.rowWidths firstObject] floatValue];
  369. if (x != self.edgeInsets.left) {
  370. x += self.columnMargin;
  371. }
  372. //更新内容的宽度
  373. [self.rowWidths replaceObjectAtIndex:0 withObject:@(x + w)];
  374. //记录内容的宽度
  375. self.maxRowWidth = [[self.rowWidths firstObject] floatValue];
  376. return CGRectMake(x, y, w, h);
  377. }
  378. //返回头视图的布局frame
  379. - (CGRect)headerViewFrameOfVerticalWaterFlow:(NSIndexPath *)indexPath{
  380. CGSize size = CGSizeZero;
  381. if([self.delegate respondsToSelector:@selector(waterFlowLayout:sizeForHeaderViewInSection:)]){
  382. size = [self.delegate waterFlowLayout:self sizeForHeaderViewInSection:indexPath.section];
  383. }
  384. if (self.flowLayoutStyle == WSLVerticalWaterFlow) {
  385. CGFloat x = 0;
  386. CGFloat y = self.maxColumnHeight == 0 ? self.edgeInsets.top : self.maxColumnHeight;
  387. if (![self.delegate respondsToSelector:@selector(waterFlowLayout:sizeForFooterViewInSection:)] || [self.delegate waterFlowLayout:self sizeForFooterViewInSection:indexPath.section].height == 0) {
  388. y = self.maxColumnHeight == 0 ? self.edgeInsets.top : self.maxColumnHeight + self.rowMargin;
  389. }
  390. self.maxColumnHeight = y + size.height ;
  391. [self.columnHeights removeAllObjects];
  392. for (NSInteger i = 0; i < self.columnCount; i++) {
  393. [self.columnHeights addObject:@(self.maxColumnHeight)];
  394. }
  395. return CGRectMake(x , y, self.collectionView.frame.size.width, size.height);
  396. }else if (self.flowLayoutStyle == WSLVHWaterFlow){
  397. CGFloat x = 0;
  398. CGFloat y = self.maxColumnHeight == 0 ? self.edgeInsets.top : self.maxColumnHeight;
  399. if (![self.delegate respondsToSelector:@selector(waterFlowLayout:sizeForFooterViewInSection:)] || [self.delegate waterFlowLayout:self sizeForFooterViewInSection:indexPath.section].height == 0) {
  400. y = self.maxColumnHeight == 0 ? self.edgeInsets.top : self.maxColumnHeight + self.rowMargin;
  401. }
  402. self.maxColumnHeight = y + size.height ;
  403. [self.rowWidths replaceObjectAtIndex:0 withObject:@(self.collectionView.frame.size.width)];
  404. [self.columnHeights replaceObjectAtIndex:0 withObject:@(self.maxColumnHeight)];
  405. return CGRectMake(x , y, self.collectionView.frame.size.width, size.height);
  406. }else if (self.flowLayoutStyle == WSLHorizontalWaterFlow){
  407. }
  408. return CGRectMake(0, 0, 0, 0);
  409. }
  410. //返回脚视图的布局frame
  411. - (CGRect)footerViewFrameOfVerticalWaterFlow:(NSIndexPath *)indexPath{
  412. CGSize size = CGSizeZero;
  413. if([self.delegate respondsToSelector:@selector(waterFlowLayout:sizeForFooterViewInSection:)]){
  414. size = [self.delegate waterFlowLayout:self sizeForFooterViewInSection:indexPath.section];
  415. }
  416. if (self.flowLayoutStyle == WSLVerticalWaterFlow ) {
  417. CGFloat x = 0;
  418. CGFloat y = size.height == 0 ? self.maxColumnHeight : self.maxColumnHeight + self.rowMargin;
  419. self.maxColumnHeight = y + size.height;
  420. [self.columnHeights removeAllObjects];
  421. for (NSInteger i = 0; i < self.columnCount; i++) {
  422. [self.columnHeights addObject:@(self.maxColumnHeight)];
  423. }
  424. return CGRectMake(x , y, self.collectionView.frame.size.width, size.height);
  425. }else if (self.flowLayoutStyle == WSLVHWaterFlow){
  426. CGFloat x = 0;
  427. CGFloat y = size.height == 0 ? self.maxColumnHeight : self.maxColumnHeight + self.rowMargin;
  428. self.maxColumnHeight = y + size.height;
  429. [self.rowWidths replaceObjectAtIndex:0 withObject:@(self.collectionView.frame.size.width)];
  430. [self.columnHeights replaceObjectAtIndex:0 withObject:@(self.maxColumnHeight)];
  431. return CGRectMake(x , y, self.collectionView.frame.size.width, size.height);
  432. }else if (self.flowLayoutStyle == WSLHorizontalWaterFlow){
  433. }
  434. return CGRectMake(0, 0, 0, 0);
  435. }
  436. @end