JXCategoryTitleVerticalZoomView.m 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // JXCategoryTitleVerticalZoomView.m
  3. // JXCategoryView
  4. //
  5. // Created by jiaxin on 2019/2/14.
  6. // Copyright © 2019 jiaxin. All rights reserved.
  7. //
  8. #import "JXCategoryTitleVerticalZoomView.h"
  9. #import "JXCategoryTitleVerticalZoomCellModel.h"
  10. #import "JXCategoryTitleVerticalZoomCell.h"
  11. #import "JXCategoryFactory.h"
  12. @interface JXCategoryTitleVerticalZoomView ()
  13. @property (nonatomic, assign) CGFloat currentVerticalScale; //当前垂直方向的缩放基准值
  14. @end
  15. @implementation JXCategoryTitleVerticalZoomView
  16. - (void)initializeData {
  17. [super initializeData];
  18. _maxVerticalFontScale = 2;
  19. _minVerticalFontScale = 1.3;
  20. _currentVerticalScale = _maxVerticalFontScale;
  21. self.cellWidthZoomEnabled = YES;
  22. self.cellWidthZoomScale = _maxVerticalFontScale;
  23. self.contentEdgeInsetLeft = 15;
  24. self.titleLabelZoomScale = _currentVerticalScale;
  25. self.titleLabelZoomEnabled = YES;
  26. self.selectedAnimationEnabled = YES;
  27. _maxVerticalCellSpacing = 20;
  28. _minVerticalCellSpacing = 10;
  29. self.cellSpacing = _maxVerticalCellSpacing;
  30. }
  31. - (void)listDidScrollWithVerticalHeightPercent:(CGFloat)percent {
  32. CGFloat currentScale = [JXCategoryFactory interpolationFrom:self.minVerticalFontScale to:self.maxVerticalFontScale percent:percent];
  33. BOOL shouldReloadData = NO;
  34. if (self.currentVerticalScale != currentScale) {
  35. //有变化才允许reloadData
  36. shouldReloadData = YES;
  37. }
  38. self.currentVerticalScale = currentScale;
  39. self.cellWidthZoomScale = currentScale;
  40. self.cellSpacing = [JXCategoryFactory interpolationFrom:self.minVerticalCellSpacing to:self.maxVerticalCellSpacing percent:percent];
  41. if (shouldReloadData) {
  42. [self refreshDataSource];
  43. [self refreshState];
  44. [self.collectionView.collectionViewLayout invalidateLayout];
  45. [self.collectionView reloadData];
  46. }
  47. }
  48. - (void)setCurrentVerticalScale:(CGFloat)currentVerticalScale {
  49. _currentVerticalScale = currentVerticalScale;
  50. self.titleLabelZoomScale = currentVerticalScale;
  51. }
  52. - (void)setMaxVerticalCellSpacing:(CGFloat)maxVerticalCellSpacing {
  53. _maxVerticalCellSpacing = maxVerticalCellSpacing;
  54. self.cellSpacing = maxVerticalCellSpacing;
  55. }
  56. - (void)setMaxVerticalFontScale:(CGFloat)maxVerticalFontScale {
  57. _maxVerticalFontScale = maxVerticalFontScale;
  58. self.titleLabelZoomScale = maxVerticalFontScale;
  59. self.cellWidthZoomScale = maxVerticalFontScale;
  60. }
  61. - (Class)preferredCellClass {
  62. return [JXCategoryTitleVerticalZoomCell class];
  63. }
  64. - (void)refreshDataSource {
  65. NSMutableArray *tempArray = [NSMutableArray array];
  66. for (int i = 0; i < self.titles.count; i++) {
  67. JXCategoryTitleVerticalZoomCellModel *cellModel = [[JXCategoryTitleVerticalZoomCellModel alloc] init];
  68. [tempArray addObject:cellModel];
  69. }
  70. self.dataSource = tempArray;
  71. }
  72. - (void)refreshCellModel:(JXCategoryBaseCellModel *)cellModel index:(NSInteger)index {
  73. [super refreshCellModel:cellModel index:index];
  74. JXCategoryTitleVerticalZoomCellModel *model = (JXCategoryTitleVerticalZoomCellModel *)cellModel;
  75. model.maxVerticalFontScale = self.maxVerticalFontScale;
  76. }
  77. @end