UITableView-BMDynamicLayout 3.1.5

UITableView-BMDynamicLayout 3.1.5

idhong 维护。



  • 作者:
  • liangdahong

UITableView-BMDynamicLayout

演示

介绍

  • 这是一个自动计算和缓存高度的模板自动布局单元格框架。
  • 本框架是一个方便的、高性能的自动计算采用 Autolayout 布局的 UITableViewCell 和 UITableViewHeaderFooterView 的高度,同时支持横竖屏,Masonry 等采用系统 Autolayout 布局的框架,同时自动处理高度缓存,

CocoaPods

pod 'UITableView-BMDynamicLayout'
pod install
#import "BMTableViewDynamicLayout.h"

使用

如果你想使用这个框架,你的 Cell 或 UITableViewHeaderFooterView 必须使用 Autolayout 布局,并确保其中一个 View 的最大 Y 坐标正好是 Cell 或UITableViewHeaderFooterView 需要的高度。

  • 在下面的 Cell 布局中,箭头所指的 View 的最大 Y 值正是该 Cell 所需的高度。

计算 Cell 的高度

/// 获取 Cell 需要的高度 ,内部无缓存操作
/// @param clas cell class
/// @param configuration 布局 cell
- (CGFloat)bm_heightWithCellClass:(Class)clas
                    configuration:(void (^)(__kindof UITableViewCell *cell))configuration;

/// 获取 Cell 需要的高度 ,内部自动处理缓存,缓存标识 indexPath
/// @param clas cell class
/// @param indexPath 使用 indexPath 做缓存标识
/// @param configuration 布局 cell
- (CGFloat)bm_heightWithCellClass:(Class)clas
                 cacheByIndexPath:(NSIndexPath *)indexPath
                    configuration:(void (^)(__kindof UITableViewCell *cell))configuration;

/// 获取 Cell 需要的高度 ,内部自动处理缓存,缓存标识 key
/// @param clas cell class
/// @param key 使用 key 做缓存标识
/// @param configuration 布局 cell
- (CGFloat)bm_heightWithCellClass:(Class)clas
                       cacheByKey:(NSString *)key
                    configuration:(void (^)(__kindof UITableViewCell *cell))configuration;

计算UITableViewHeaderFooterView的高度

/// 获取 HeaderFooter 需要的高度 ,内部无缓存操作
/// @param clas HeaderFooter class
/// @param type HeaderFooter类型,Header 或者 Footer
/// @param configuration 布局 HeaderFooter
- (CGFloat)bm_heightWithHeaderFooterViewClass:(Class)clas
                                         type:(BMHeaderFooterViewDynamicLayoutType)type
                                configuration:(void (^)(__kindof UITableViewHeaderFooterView *headerFooterView))configuration;

/// 获取 HeaderFooter 需要的高度 , 内部自动处理缓存,缓存标识 section
/// @param clas HeaderFooter class
/// @param type HeaderFooter类型,Header 或者 Footer
/// @param section 使用 section 做缓存标识
/// @param configuration 布局 HeaderFooter
- (CGFloat)bm_heightWithHeaderFooterViewClass:(Class)clas
                                         type:(BMHeaderFooterViewDynamicLayoutType)type
                               cacheBySection:(NSInteger)section
                                configuration:(void (^)(__kindof UITableViewHeaderFooterView *headerFooterView))configuration;

/// 获取 HeaderFooter 需要的高度 , 内部自动处理缓存,缓存标识 key
/// @param clas HeaderFooter class
/// @param type HeaderFooter类型,Header 或者 Footer
/// @param key 使用 key 做缓存标识
/// @param configuration 布局 HeaderFooter
- (CGFloat)bm_heightWithHeaderFooterViewClass:(Class)clas
                                         type:(BMHeaderFooterViewDynamicLayoutType)type
                                   cacheByKey:(NSString *)key
                                configuration:(void (^)(__kindof UITableViewHeaderFooterView *headerFooterView))configuration;

优化配置项

Cell

/// 如果你的 Cell 中用来确定 Cell 所需高度的 View 是唯一的,
/// 请把此值设置为 YES,可提升一定的性能。
@property (nonatomic, assign) IBInspectable BOOL bm_maxYViewFixed;

HeaderFooterView

/// 如果你的 HeaderFooterView 中用来确定 HeaderFooterView 所需高度的 View 是唯一的,
/// 请把此值设置为 YES,可提升一定的性能。
@property (nonatomic, assign) IBInspectable BOOL bm_maxYViewFixed;

许可

UITableView-BMDynamicLayout 在 MIT 许可下发布。有关详细信息,请参阅 LICENSE 文件。