UITableViewCell+HYBMasonryAutoCellHeight.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // UITableViewCell+HYBMasonryAutoCellHeight.h
  3. // CellAutoHeightDemo
  4. //
  5. // Created by huangyibiao on 15/9/1.
  6. // Copyright © 2015年 huangyibiao. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "UITableView+HYBCacheHeight.h"
  10. /**
  11. * 获取高度前会回调,需要在此BLOCK中配置数据,才能正确地获取高度
  12. */
  13. typedef void(^HYBCellBlock)(UITableViewCell *sourceCell);
  14. typedef NSDictionary *(^HYBCacheHeight)();
  15. /**
  16. * @author 黄仪标, 16-01-22 21:01:09
  17. *
  18. * 唯一键,通常是数据模型的id,保证唯一
  19. */
  20. FOUNDATION_EXTERN NSString *const kHYBCacheUniqueKey;
  21. /**
  22. * @author 黄仪标, 16-01-22 21:01:57
  23. *
  24. * 对于同一个model,如果有不同状态,而且不同状态下高度不一样,那么也需要指定
  25. */
  26. FOUNDATION_EXTERN NSString *const kHYBCacheStateKey;
  27. /**
  28. * @author 黄仪标, 16-01-22 21:01:47
  29. *
  30. * 用于指定更新某种状态的缓存,比如当评论时,增加了一条评论,此时该状态的高度若已经缓存过,则需要指定来更新缓存
  31. */
  32. FOUNDATION_EXTERN NSString *const kHYBRecalculateForStateKey;
  33. /**
  34. * 基于Masonry自动布局实现的自动计算cell的行高扩展
  35. *
  36. * @author huangyibiao
  37. * @email huangyibiao520@163.com
  38. * @github https://github.com/CoderJackyHuang
  39. * @blog http://www.henishuo.com/masonry-cell-height-auto-calculate/
  40. *
  41. * @note Make friends with me:
  42. * QQ:(632840804)
  43. * Please tell me your real name when you send message to me.3Q.
  44. */
  45. @interface UITableViewCell (HYBMasonryAutoCellHeight)
  46. /************************************************************************
  47. *
  48. * @note UI布局必须放在UITableViewCell的初始化方法中:
  49. *
  50. * - initWithStyle:reuseIdentifier:
  51. *
  52. * 且必须指定hyb_lastViewInCell才能生效
  53. ************************************************************************/
  54. /**
  55. * 必传设置的属性,也就是在cell中的contentView内最后一个视图,用于计算行高
  56. * 例如,创建了一个按钮button作为在cell中放到最后一个位置,则设置为:self.hyb_lastVieInCell = button;
  57. * 即可。
  58. * 默认为nil,如果在计算时,值为nil,会crash (弃用)
  59. */
  60. @property (nonatomic, strong) UIView *hyb_lastViewInCell;
  61. /**
  62. * 当距离分割线的视图不确定时,可以将可能的所有视图放在这个数组里面,优先级低于上面的属性,也就是当`hyb_lastViewInCell`有值时,`hyb_lastViewsInCell`不起作用。(弃用)
  63. */
  64. @property (nonatomic, strong) NSArray *hyb_lastViewsInCell;
  65. /**
  66. * 可选设置的属性,默认为0,表示指定的hyb_lastViewInCell到cell的bottom的距离
  67. * 默认为0.0
  68. */
  69. @property (nonatomic, assign) CGFloat hyb_bottomOffsetToCell;
  70. /**
  71. * 通过此方法来计算行高,需要在config中调用配置数据的API
  72. *
  73. * @param tableView 必传,为哪个tableView缓存行高
  74. * @param config 必须要实现,且需要调用配置数据的API
  75. *
  76. * @return 计算的行高
  77. */
  78. + (CGFloat)hyb_heightForTableView:(UITableView *)tableView config:(HYBCellBlock)config;
  79. /**
  80. * @author 黄仪标, 16-01-22 23:01:56
  81. *
  82. * 此API会缓存行高
  83. *
  84. * @param tableView 必传,为哪个tableView缓存行高
  85. * @param config 必须要实现,且需要调用配置数据的API
  86. * @param cache 返回相关key
  87. *
  88. * @return 行高
  89. */
  90. + (CGFloat)hyb_heightForTableView:(UITableView *)tableView
  91. config:(HYBCellBlock)config
  92. cache:(HYBCacheHeight)cache;
  93. @end