JXCategoryBaseCell.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // JXCategoryBaseCell.m
  3. // UI系列测试
  4. //
  5. // Created by jiaxin on 2018/3/15.
  6. // Copyright © 2018年 jiaxin. All rights reserved.
  7. //
  8. #import "JXCategoryBaseCell.h"
  9. @interface JXCategoryBaseCell ()
  10. @property (nonatomic, strong) JXCategoryBaseCellModel *cellModel;
  11. @property (nonatomic, strong) JXCategoryViewAnimator *animator;
  12. @property (nonatomic, strong) NSMutableArray <JXCategoryCellSelectedAnimationBlock> *animationBlockArray;
  13. @end
  14. @implementation JXCategoryBaseCell
  15. - (void)dealloc
  16. {
  17. [self.animator stop];
  18. }
  19. - (void)prepareForReuse {
  20. [super prepareForReuse];
  21. [self.animator stop];
  22. }
  23. - (instancetype)initWithFrame:(CGRect)frame {
  24. self = [super initWithFrame:frame];
  25. if (self) {
  26. [self initializeViews];
  27. }
  28. return self;
  29. }
  30. - (void)initializeViews {
  31. _animationBlockArray = [NSMutableArray array];
  32. }
  33. - (void)reloadData:(JXCategoryBaseCellModel *)cellModel {
  34. self.cellModel = cellModel;
  35. if (cellModel.isSelectedAnimationEnabled) {
  36. [self.animationBlockArray removeLastObject];
  37. if ([self checkCanStartSelectedAnimation:cellModel]) {
  38. _animator = [[JXCategoryViewAnimator alloc] init];
  39. self.animator.duration = cellModel.selectedAnimationDuration;
  40. }else {
  41. [self.animator stop];
  42. }
  43. }
  44. }
  45. - (BOOL)checkCanStartSelectedAnimation:(JXCategoryBaseCellModel *)cellModel {
  46. if (cellModel.selectedType == JXCategoryCellSelectedTypeCode || cellModel.selectedType == JXCategoryCellSelectedTypeClick) {
  47. return YES;
  48. }
  49. return NO;
  50. }
  51. - (void)addSelectedAnimationBlock:(JXCategoryCellSelectedAnimationBlock)block {
  52. [self.animationBlockArray addObject:block];
  53. }
  54. - (void)startSelectedAnimationIfNeeded:(JXCategoryBaseCellModel *)cellModel {
  55. if (cellModel.isSelectedAnimationEnabled && [self checkCanStartSelectedAnimation:cellModel]) {
  56. //需要更新isTransitionAnimating,用于处理在过滤时,禁止响应点击,避免界面异常。
  57. cellModel.transitionAnimating = YES;
  58. __weak typeof(self)weakSelf = self;
  59. self.animator.progressCallback = ^(CGFloat percent) {
  60. for (JXCategoryCellSelectedAnimationBlock block in weakSelf.animationBlockArray) {
  61. block(percent);
  62. }
  63. };
  64. self.animator.completeCallback = ^{
  65. cellModel.transitionAnimating = NO;
  66. [weakSelf.animationBlockArray removeAllObjects];
  67. };
  68. [self.animator start];
  69. }
  70. }
  71. @end