CGXVerticalMenuIndicatorLineView.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //
  2. // CGXHomeCategoryIndicatorLineView.m
  3. // CGXVerticalMenuView-OC
  4. //
  5. // Created by CGX on 2018/05/01.
  6. // Copyright © 2019 CGX. All rights reserved.
  7. //
  8. #import "CGXVerticalMenuIndicatorLineView.h"
  9. @implementation CGXVerticalMenuIndicatorLineView
  10. - (void)initializeData
  11. {
  12. [super initializeData];
  13. self.positionType = CGXVerticalMenuIndicatorLinePosition_Left;
  14. self.spaceTop = 0;
  15. self.spaceLeft = 0;
  16. self.spaceRight = 0;
  17. self.spaceBottom = 0;
  18. self.lineSpace = 4;
  19. }
  20. - (void)initializeViews
  21. {
  22. [super initializeViews];
  23. self.backgroundColor = [UIColor redColor];
  24. }
  25. /**
  26. categoryView重置状态时调用
  27. param selectedIndex 当前选中的index
  28. param selectedCellFrame 当前选中的cellFrame
  29. @param model 数据模型
  30. */
  31. - (void)listIndicatorRefreshState:(CGXVerticalMenuIndicatorParamsModel *)model
  32. {
  33. // NSLog(@"RefreshState---%@" , model);
  34. [self updateIndicatorModel:model];
  35. }
  36. /**
  37. 选中了某一个cell
  38. param lastSelectedIndex 之前选中的index
  39. param selectedIndex 选中的index
  40. param selectedCellFrame 选中的cellFrame
  41. param selectedType cell被选中类型
  42. @param model 数据模型
  43. */
  44. - (void)listIndicatorSelectedCell:(CGXVerticalMenuIndicatorParamsModel *)model
  45. {
  46. // NSLog(@"SelectedCell---%@" , model);
  47. [self updateIndicatorModel:model];
  48. }
  49. - (void)updateIndicatorModel:(CGXVerticalMenuIndicatorParamsModel *)model
  50. {
  51. CGRect lineFrame;
  52. CGFloat x = 0;
  53. CGFloat y = 0;
  54. CGFloat w = 0;
  55. CGFloat h = 0;
  56. switch (self.positionType) {
  57. case CGXVerticalMenuIndicatorLinePosition_Left:
  58. {
  59. x = self.spaceLeft;
  60. y = self.spaceTop+model.selectedIndex * (model.selectedCellFrame.size.height+0)+0;
  61. w = self.lineSpace;
  62. h = model.selectedCellFrame.size.height-self.spaceTop-self.spaceBottom;
  63. }
  64. break;
  65. case CGXVerticalMenuIndicatorLinePosition_Right:
  66. {
  67. x = model.selectedCellFrame.size.width-self.lineSpace-self.spaceRight;
  68. y = self.spaceTop+model.selectedIndex * (model.selectedCellFrame.size.height+0)+0;
  69. w = self.lineSpace;
  70. h = model.selectedCellFrame.size.height-self.spaceTop-self.spaceBottom;
  71. }
  72. break;
  73. case CGXVerticalMenuIndicatorLinePosition_Top:
  74. {
  75. x = self.spaceLeft;
  76. y = self.spaceTop+model.selectedIndex * (model.selectedCellFrame.size.height+0)+0;
  77. w = model.selectedCellFrame.size.width-self.spaceLeft-self.spaceRight;;
  78. h = self.lineSpace;
  79. }
  80. break;
  81. case CGXVerticalMenuIndicatorLinePosition_Bottom:
  82. {
  83. x = self.spaceLeft;
  84. y = model.selectedCellFrame.size.height - self.spaceBottom - self.lineSpace + model.selectedIndex * (model.selectedCellFrame.size.height+0)+0;
  85. w = model.selectedCellFrame.size.width-self.spaceLeft-self.spaceRight;;
  86. h = self.lineSpace;
  87. }
  88. break;
  89. default:
  90. break;
  91. }
  92. lineFrame = CGRectMake(x, y, w, h);
  93. if (model.isFirstClick) {
  94. [UIView animateWithDuration:0 animations:^{
  95. self.frame = lineFrame;
  96. }];
  97. } else{
  98. [UIView animateWithDuration:model.timeDuration animations:^{
  99. self.frame = lineFrame;
  100. }];
  101. }
  102. }
  103. /*
  104. // Only override drawRect: if you perform custom drawing.
  105. // An empty implementation adversely affects performance during animation.
  106. - (void)drawRect:(CGRect)rect {
  107. // Drawing code
  108. }
  109. */
  110. @end