CGXVerticalMenuIndicatorBackgroundView.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // CGXVerticalMenuIndicatorBackgroundView.m
  3. // CGXVerticalMenuView-OC
  4. //
  5. // Created by CGX on 2018/05/01.
  6. // Copyright © 2019 CGX. All rights reserved.
  7. //
  8. #import "CGXVerticalMenuIndicatorBackgroundView.h"
  9. @implementation CGXVerticalMenuIndicatorBackgroundView
  10. - (void)initializeData
  11. {
  12. [super initializeData];
  13. self.backgroundViewColor = [UIColor whiteColor];
  14. self.backgroundViewWidth = CGXVerticalMenuViewAutomaticDimension;
  15. self.backgroundViewHeight = CGXVerticalMenuViewAutomaticDimension;
  16. self.backgroundViewCornerRadius = CGXVerticalMenuViewAutomaticDimension;
  17. }
  18. - (void)initializeViews
  19. {
  20. [super initializeViews];
  21. self.backgroundColor = self.backgroundViewColor;
  22. self.layer.masksToBounds =YES;
  23. }
  24. - (void)layoutSubviews
  25. {
  26. [super layoutSubviews];
  27. CGRect backframe = self.bounds;
  28. if (self.backgroundViewCornerRadius == CGXVerticalMenuViewAutomaticDimension) {
  29. self.layer.cornerRadius = CGRectGetHeight(self.frame)/2.0;
  30. } else{
  31. self.layer.cornerRadius = self.backgroundViewCornerRadius;
  32. }
  33. if (self.backgroundViewWidth != CGXVerticalMenuViewAutomaticDimension) {
  34. backframe.size.width = self.backgroundViewWidth;
  35. }
  36. if (self.backgroundViewHeight != CGXVerticalMenuViewAutomaticDimension) {
  37. backframe.size.height = self.backgroundViewHeight;
  38. }
  39. }
  40. /**
  41. categoryView重置状态时调用
  42. param selectedIndex 当前选中的index
  43. param selectedCellFrame 当前选中的cellFrame
  44. @param model 数据模型
  45. */
  46. - (void)listIndicatorRefreshState:(CGXVerticalMenuIndicatorParamsModel *)model
  47. {
  48. // NSLog(@"RefreshState---%@" , model);
  49. [self updateIndicatorModel:model];
  50. }
  51. /**
  52. 选中了某一个cell
  53. param lastSelectedIndex 之前选中的index
  54. param selectedIndex 选中的index
  55. param selectedCellFrame 选中的cellFrame
  56. param selectedType cell被选中类型
  57. @param model 数据模型
  58. */
  59. - (void)listIndicatorSelectedCell:(CGXVerticalMenuIndicatorParamsModel *)model
  60. {
  61. [self updateIndicatorModel:model];
  62. }
  63. - (void)updateIndicatorModel:(CGXVerticalMenuIndicatorParamsModel *)model
  64. {
  65. CGRect backframe = model.backgroundViewMaskFrame;
  66. if (self.backgroundViewWidth != CGXVerticalMenuViewAutomaticDimension) {
  67. backframe.origin.x = (backframe.size.width - self.backgroundViewWidth)/2.0;
  68. backframe.size.width = self.backgroundViewWidth;
  69. }
  70. if (self.backgroundViewHeight != CGXVerticalMenuViewAutomaticDimension) {
  71. backframe.origin.y = (backframe.size.height - self.backgroundViewHeight)/2.0+ model.selectedIndex * (model.selectedCellFrame.size.height+0)+0;
  72. backframe.size.height = self.backgroundViewHeight;
  73. }
  74. if (model.isFirstClick) {
  75. [UIView animateWithDuration:0 animations:^{
  76. self.frame = backframe;
  77. }];
  78. } else{
  79. [UIView animateWithDuration:model.timeDuration animations:^{
  80. self.frame = backframe;
  81. }];
  82. }
  83. }
  84. @end