JXCategoryImageView.m 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // JXCategoryImageView.m
  3. // JXCategoryView
  4. //
  5. // Created by jiaxin on 2018/8/20.
  6. // Copyright © 2018年 jiaxin. All rights reserved.
  7. //
  8. #import "JXCategoryImageView.h"
  9. #import "JXCategoryFactory.h"
  10. @implementation JXCategoryImageView
  11. - (void)dealloc
  12. {
  13. self.loadImageCallback = nil;
  14. }
  15. - (void)initializeData {
  16. [super initializeData];
  17. _imageSize = CGSizeMake(20, 20);
  18. _imageZoomEnabled = NO;
  19. _imageZoomScale = 1.2;
  20. _imageCornerRadius = 0;
  21. }
  22. - (Class)preferredCellClass {
  23. return [JXCategoryImageCell class];
  24. }
  25. - (void)refreshDataSource {
  26. NSMutableArray *tempArray = [NSMutableArray array];
  27. NSUInteger count = (self.imageNames.count > 0) ? self.imageNames.count : (self.imageURLs.count > 0 ? self.imageURLs.count : 0);
  28. for (int i = 0; i < count; i++) {
  29. JXCategoryImageCellModel *cellModel = [[JXCategoryImageCellModel alloc] init];
  30. [tempArray addObject:cellModel];
  31. }
  32. self.dataSource = tempArray;
  33. }
  34. - (void)refreshSelectedCellModel:(JXCategoryBaseCellModel *)selectedCellModel unselectedCellModel:(JXCategoryBaseCellModel *)unselectedCellModel {
  35. [super refreshSelectedCellModel:selectedCellModel unselectedCellModel:unselectedCellModel];
  36. JXCategoryImageCellModel *myUnselectedCellModel = (JXCategoryImageCellModel *)unselectedCellModel;
  37. myUnselectedCellModel.imageZoomScale = 1.0;
  38. JXCategoryImageCellModel *myselectedCellModel = (JXCategoryImageCellModel *)selectedCellModel;
  39. myselectedCellModel.imageZoomScale = self.imageZoomScale;
  40. }
  41. - (void)refreshCellModel:(JXCategoryBaseCellModel *)cellModel index:(NSInteger)index {
  42. [super refreshCellModel:cellModel index:index];
  43. JXCategoryImageCellModel *myCellModel = (JXCategoryImageCellModel *)cellModel;
  44. myCellModel.loadImageCallback = self.loadImageCallback;
  45. myCellModel.imageSize = self.imageSize;
  46. myCellModel.imageCornerRadius = self.imageCornerRadius;
  47. if (self.imageNames != nil) {
  48. myCellModel.imageName = self.imageNames[index];
  49. }else if (self.imageURLs != nil) {
  50. myCellModel.imageURL = self.imageURLs[index];
  51. }
  52. if (self.selectedImageNames != nil) {
  53. myCellModel.selectedImageName = self.selectedImageNames[index];
  54. }else if (self.selectedImageURLs != nil) {
  55. myCellModel.selectedImageURL = self.selectedImageURLs[index];
  56. }
  57. myCellModel.imageZoomEnabled = self.imageZoomEnabled;
  58. myCellModel.imageZoomScale = 1.0;
  59. if (index == self.selectedIndex) {
  60. myCellModel.imageZoomScale = self.imageZoomScale;
  61. }
  62. }
  63. - (void)refreshLeftCellModel:(JXCategoryBaseCellModel *)leftCellModel rightCellModel:(JXCategoryBaseCellModel *)rightCellModel ratio:(CGFloat)ratio {
  64. [super refreshLeftCellModel:leftCellModel rightCellModel:rightCellModel ratio:ratio];
  65. JXCategoryImageCellModel *leftModel = (JXCategoryImageCellModel *)leftCellModel;
  66. JXCategoryImageCellModel *rightModel = (JXCategoryImageCellModel *)rightCellModel;
  67. if (self.isImageZoomEnabled) {
  68. leftModel.imageZoomScale = [JXCategoryFactory interpolationFrom:self.imageZoomScale to:1.0 percent:ratio];
  69. rightModel.imageZoomScale = [JXCategoryFactory interpolationFrom:1.0 to:self.imageZoomScale percent:ratio];
  70. }
  71. }
  72. - (CGFloat)preferredCellWidthAtIndex:(NSInteger)index {
  73. if (self.cellWidth == JXCategoryViewAutomaticDimension) {
  74. return self.imageSize.width;
  75. }
  76. return self.cellWidth;
  77. }
  78. @end