// // DocumentLibraryHomeVC.m // Telemarketing // // Created by apple on 2021/4/28. // Copyright © 2021 刘惠萍. All rights reserved. // #import "DocumentLibraryHomeVC.h" #import "SliderView.h" #import "DocumentLibraryListVC.h" @interface DocumentLibraryHomeVC () @property (strong, nonatomic) SliderView *sliderView; @property (nonatomic, strong) UIScrollView *scList; @property (nonatomic, strong) NSMutableArray *aryModelbtns; @property (strong, nonatomic) ModelBaseData *modelb; @end @implementation DocumentLibraryHomeVC - (NSMutableArray *)aryModelbtns{ if (!_aryModelbtns) { _aryModelbtns = [NSMutableArray new]; } return _aryModelbtns; } - (SliderView *)sliderView{ if (_sliderView == nil) { _sliderView = [SliderView new]; self.sliderView.frame = CGRectMake(0,W(5),SCREEN_WIDTH,W(44)); _sliderView.viewSlidWidth = 15; _sliderView.isHasSlider = true; _sliderView.isLineVerticalHide = true; _sliderView.viewSlidColor = COLOR_BLUE; _sliderView.delegate = self; _sliderView.isScroll=true; } return _sliderView; } - (UIScrollView *)scList{ if (!_scList) { _scList = [UIScrollView new]; self.scList = [[UIScrollView alloc]initWithFrame:CGRectMake(0, self.sliderView.bottom +1, SCREEN_WIDTH, self.scAll.height - self.sliderView.height)]; _scList.backgroundColor = [UIColor whiteColor]; _scList.delegate = self; _scList.showsVerticalScrollIndicator = false; _scList.showsHorizontalScrollIndicator = false; // _scList.contentSize = CGSizeMake(SCREEN_WIDTH * 3, 0); _scList.pagingEnabled = true; } return _scList; } - (LinkScrollView *)scAll{ if (!_scAll) { _scAll = [LinkScrollView new]; _scAll.frame = CGRectMake(0, NAVIGATIONBAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT-NAVIGATIONBAR_HEIGHT); _scAll.contentSize = CGSizeMake(0, SCREEN_HEIGHT*5); _scAll.backgroundColor = [UIColor clearColor]; _scAll.showsVerticalScrollIndicator = false; _scAll.showsHorizontalScrollIndicator = false; _scAll.delegate = self; } return _scAll; } - (void)viewDidLoad { [super viewDidLoad]; [self.view addSubview:[BaseNavView initNavBackTitle:@"文案库" rightView:nil]]; [self.view addSubview:self.scAll]; [self.scAll addSubview:self.sliderView]; self.scAll.sizeHeight = self.sliderView.top - 2; [self.scAll addSubview:self.scList]; [self requestList]; [self setupChildVC]; } #pragma mark scrollview delegat - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ if ([scrollView isEqual:self.scList]) { [self fetchCurrentView]; } } - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ if ([scrollView isEqual:self.scList]) { if (!decelerate) { [self fetchCurrentView]; } } } - (void)fetchCurrentView { // 获取已经滚动的比例 double ratio = self.scList.contentOffset.x / SCREEN_WIDTH; int page = (int)(ratio + 0.5); // scrollview 到page页时 将toolbar调至对应按钮 [self.sliderView sliderToIndex:page noticeDelegate:NO]; [self setupChildVC]; } - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{ if (scrollView == self.scAll) { if (velocity.y > 0||targetContentOffset->y>self.sliderView.top) { targetContentOffset->y = self.sliderView.top; } } } #pragma mark slider delegate - (void)protocolSliderViewBtnSelect:(NSUInteger)tag btn:(CustomSliderControl *)control{ self.scList.contentOffset = CGPointMake(SCREEN_WIDTH * tag, 0); [self setupChildVC]; } - (void)requestList{ [RequestApi requestGetInformationTypeNameWithDelegate:self success:^(NSDictionary * _Nonnull response, id _Nonnull mark) { NSArray * ary = [GlobalMethod exchangeDic:response[@"data"] toAryWithModelName:@"ModelBrand"]; [self.aryModelbtns removeAllObjects]; [self.aryModelbtns addObject:[ModelBtn modelWithTitle:@"全部" imageName:nil highImageName:nil tag:0 color:COLOR_999 selectColor:COLOR_BLUE]]; for (int i =0; i