DocumentLibraryHomeVC.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //
  2. // DocumentLibraryHomeVC.m
  3. // Telemarketing
  4. //
  5. // Created by apple on 2021/4/28.
  6. // Copyright © 2021 刘惠萍. All rights reserved.
  7. //
  8. #import "DocumentLibraryHomeVC.h"
  9. #import "SliderView.h"
  10. #import "DocumentLibraryListVC.h"
  11. @interface DocumentLibraryHomeVC ()<SliderViewDelegate,UIScrollViewDelegate>
  12. @property (strong, nonatomic) SliderView *sliderView;
  13. @property (nonatomic, strong) UIScrollView *scList;
  14. @property (nonatomic, strong) NSMutableArray *aryModelbtns;
  15. @property (strong, nonatomic) ModelBaseData *modelb;
  16. @end
  17. @implementation DocumentLibraryHomeVC
  18. - (NSMutableArray *)aryModelbtns{
  19. if (!_aryModelbtns) {
  20. _aryModelbtns = [NSMutableArray new];
  21. }
  22. return _aryModelbtns;
  23. }
  24. - (SliderView *)sliderView{
  25. if (_sliderView == nil) {
  26. _sliderView = [SliderView new];
  27. self.sliderView.frame = CGRectMake(0,W(5),SCREEN_WIDTH,W(44));
  28. _sliderView.viewSlidWidth = 15;
  29. _sliderView.isHasSlider = true;
  30. _sliderView.isLineVerticalHide = true;
  31. _sliderView.viewSlidColor = COLOR_BLUE;
  32. _sliderView.delegate = self;
  33. _sliderView.isScroll=true;
  34. }
  35. return _sliderView;
  36. }
  37. - (UIScrollView *)scList{
  38. if (!_scList) {
  39. _scList = [UIScrollView new];
  40. self.scList = [[UIScrollView alloc]initWithFrame:CGRectMake(0, self.sliderView.bottom +1, SCREEN_WIDTH, self.scAll.height - self.sliderView.height)];
  41. _scList.backgroundColor = [UIColor whiteColor];
  42. _scList.delegate = self;
  43. _scList.showsVerticalScrollIndicator = false;
  44. _scList.showsHorizontalScrollIndicator = false;
  45. // _scList.contentSize = CGSizeMake(SCREEN_WIDTH * 3, 0);
  46. _scList.pagingEnabled = true;
  47. }
  48. return _scList;
  49. }
  50. - (LinkScrollView *)scAll{
  51. if (!_scAll) {
  52. _scAll = [LinkScrollView new];
  53. _scAll.frame = CGRectMake(0, NAVIGATIONBAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT-NAVIGATIONBAR_HEIGHT);
  54. _scAll.contentSize = CGSizeMake(0, SCREEN_HEIGHT*5);
  55. _scAll.backgroundColor = [UIColor clearColor];
  56. _scAll.showsVerticalScrollIndicator = false;
  57. _scAll.showsHorizontalScrollIndicator = false;
  58. _scAll.delegate = self;
  59. }
  60. return _scAll;
  61. }
  62. - (void)viewDidLoad {
  63. [super viewDidLoad];
  64. [self.view addSubview:[BaseNavView initNavBackTitle:@"文案库" rightView:nil]];
  65. [self.view addSubview:self.scAll];
  66. [self.scAll addSubview:self.sliderView];
  67. self.scAll.sizeHeight = self.sliderView.top - 2;
  68. [self.scAll addSubview:self.scList];
  69. [self requestList];
  70. [self setupChildVC];
  71. }
  72. #pragma mark scrollview delegat
  73. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
  74. if ([scrollView isEqual:self.scList]) {
  75. [self fetchCurrentView];
  76. }
  77. }
  78. - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
  79. if ([scrollView isEqual:self.scList]) {
  80. if (!decelerate) {
  81. [self fetchCurrentView];
  82. }
  83. }
  84. }
  85. - (void)fetchCurrentView {
  86. // 获取已经滚动的比例
  87. double ratio = self.scList.contentOffset.x / SCREEN_WIDTH;
  88. int page = (int)(ratio + 0.5);
  89. // scrollview 到page页时 将toolbar调至对应按钮
  90. [self.sliderView sliderToIndex:page noticeDelegate:NO];
  91. [self setupChildVC];
  92. }
  93. - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
  94. if (scrollView == self.scAll) {
  95. if (velocity.y > 0||targetContentOffset->y>self.sliderView.top) {
  96. targetContentOffset->y = self.sliderView.top;
  97. }
  98. }
  99. }
  100. #pragma mark slider delegate
  101. - (void)protocolSliderViewBtnSelect:(NSUInteger)tag btn:(CustomSliderControl *)control{
  102. self.scList.contentOffset = CGPointMake(SCREEN_WIDTH * tag, 0);
  103. [self setupChildVC];
  104. }
  105. - (void)requestList{
  106. [RequestApi requestGetInformationTypeNameWithDelegate:self success:^(NSDictionary * _Nonnull response, id _Nonnull mark) {
  107. NSArray * ary = [GlobalMethod exchangeDic:response[@"data"] toAryWithModelName:@"ModelBrand"];
  108. [self.aryModelbtns removeAllObjects];
  109. [self.aryModelbtns addObject:[ModelBtn modelWithTitle:@"全部" imageName:nil highImageName:nil tag:0 color:COLOR_999 selectColor:COLOR_BLUE]];
  110. for (int i =0; i<ary.count; i++) {
  111. ModelBrand *modelL = ary[i];
  112. ModelBtn * modelAll = [ModelBtn new];
  113. modelAll.title = modelL.name;
  114. modelAll.color = COLOR_666;
  115. modelAll.colorSelect = COLOR_BLUE;
  116. modelAll.vcName = modelL.internalBaseClassIdentifier;
  117. [self.aryModelbtns addObject:modelAll];
  118. }
  119. [self.sliderView resetWithAry:self.aryModelbtns];
  120. [self setupChildVC];
  121. } failure:^(NSString * _Nonnull errorStr, id _Nonnull mark) {
  122. }];
  123. }
  124. - (void)setupChildVC{
  125. [self.scList removeAllSubViews];
  126. for ( int i = 0; i<self.aryModelbtns.count; i++) {
  127. ModelBtn *modelL = self.aryModelbtns[i];
  128. DocumentLibraryListVC * vc = [[DocumentLibraryListVC alloc] init];
  129. [self addChildViewController:vc];
  130. vc.view.frame = CGRectMake(SCREEN_WIDTH*i, 0, SCREEN_WIDTH, self.scList.height-W(10));
  131. vc.tableView.frame = vc.view.bounds;
  132. vc.activeStatus=isStr(modelL.vcName)?modelL.vcName:@"FFFFFF";
  133. [vc refreshHeaderAll];
  134. [self.scList addSubview:vc.view];
  135. }
  136. self.scList.contentSize = CGSizeMake(SCREEN_WIDTH * self.aryModelbtns.count, 0);
  137. }
  138. @end