JXCategoryTitleVerticalZoomCell.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // JXCategoryTitleVerticalZoomCell.m
  3. // JXCategoryView
  4. //
  5. // Created by jiaxin on 2019/2/14.
  6. // Copyright © 2019 jiaxin. All rights reserved.
  7. //
  8. #import "JXCategoryTitleVerticalZoomCell.h"
  9. #import "JXCategoryTitleVerticalZoomCellModel.h"
  10. @implementation JXCategoryTitleVerticalZoomCell
  11. - (void)reloadData:(JXCategoryBaseCellModel *)cellModel {
  12. [super reloadData:cellModel];
  13. JXCategoryTitleVerticalZoomCellModel *myCellModel = (JXCategoryTitleVerticalZoomCellModel *)cellModel;
  14. if (myCellModel.isTitleLabelZoomEnabled) {
  15. //先把font设置为缩放的最大值,再缩小到最小值,最后根据当前的titleLabelZoomScale值,进行缩放更新。这样就能避免transform从小到大时字体模糊
  16. UIFont *maxScaleFont = [UIFont fontWithDescriptor:myCellModel.titleFont.fontDescriptor size:myCellModel.titleFont.pointSize*myCellModel.maxVerticalFontScale];
  17. CGFloat baseScale = myCellModel.titleFont.lineHeight/maxScaleFont.lineHeight;
  18. if (myCellModel.isSelectedAnimationEnabled && [self checkCanStartSelectedAnimation:myCellModel]) {
  19. JXCategoryCellSelectedAnimationBlock block = [self preferredTitleZoomAnimationBlock:myCellModel baseScale:baseScale];
  20. [self addSelectedAnimationBlock:block];
  21. }else {
  22. self.titleLabel.font = maxScaleFont;
  23. self.maskTitleLabel.font = maxScaleFont;
  24. CGAffineTransform currentTransform = CGAffineTransformMakeScale(baseScale*myCellModel.titleLabelCurrentZoomScale, baseScale*myCellModel.titleLabelCurrentZoomScale);
  25. self.titleLabel.transform = currentTransform;
  26. self.maskTitleLabel.transform = currentTransform;
  27. }
  28. }else {
  29. if (myCellModel.isSelected) {
  30. self.titleLabel.font = myCellModel.titleSelectedFont;
  31. self.maskTitleLabel.font = myCellModel.titleSelectedFont;
  32. }else {
  33. self.titleLabel.font = myCellModel.titleFont;
  34. self.maskTitleLabel.font = myCellModel.titleFont;
  35. }
  36. }
  37. [self.titleLabel sizeToFit];
  38. }
  39. @end