123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413 |
- //
- // FSBaseViewController.m
- // FSScrollViewNestTableViewDemo
- //
- // Created by huim on 2017/5/23.
- // Copyright © 2017年 fengshun. All rights reserved.
- //
- #import "FSBaseViewController.h"
- #import "FSBaseTableView.h"
- #import "FSBaseTopTableViewCell.h"
- #import "FSScrollContentView.h"
- #import "FSScrollContentViewController.h"
- #import "FSBottomTableViewCell.h"
- #import "HCHomeChannelModel.h"
- #import "ActivityIndicatorView.h"
- #import "LDMorePicCollectionModel.h"
- #import "LDSearchCoupleWebViewController.h"
- #import "LDSuperListModel.h"
- #import <AlibabaAuthSDK/ALBBSession.h>
- #import "AccountTool.h"
- #import <AlibabaAuthSDK/ALBBSDK.h>
- #import "HCLoginViewController.h"
- @interface FSBaseViewController ()<UITableViewDelegate,UITableViewDataSource,FSPageContentViewDelegate,FSSegmentTitleViewDelegate,YHMorePicCollectionCellDelegate>
- {
- UILabel *titleLabel;
- NSMutableArray *contentVCs;
- FSBaseTopTableViewCell *cell;
- //默认选中的model
- HCHomeChannelModel *selectModel;
- NSInteger selectIndex;//选中的下标
-
- }
- @property (nonatomic, strong) FSBaseTableView *tableView;
- @property (nonatomic, strong) FSBottomTableViewCell *contentCell;
- @property (nonatomic, strong) FSSegmentTitleView *titleView;
- @property (nonatomic, assign) BOOL canScroll;
- @property (nonatomic, strong) NSArray *morePicCollectionArr;
- @property (nonatomic, strong) NSMutableArray *modelArr;
- @property (nonatomic, strong) NSMutableArray *titleArr;
- @property (nonatomic, strong) NSMutableArray *vcArray;
- @end
- @implementation FSBaseViewController
- - (void)dealloc
- {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- #pragma mark-----viewDidLoad
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor =[UIColor whiteColor];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeScrollStatus) name:@"leaveTop" object:nil];
- [self loadChildViewController];
- [self setupSubViews];
- [self.view addSubview:self.tableView];
- [self loadHotRecomPicCollectionData];
- }
- /**
- 加载菜单栏目
- */
- - (void)loadHotRecomPicCollectionData {
- [HCHttp get:GoldCollectiongroups params:nil success:^(id json) {
- self.morePicCollectionArr = [NSArray yy_modelArrayWithClass:[LDMorePicCollectionModel class] json:json[@"data"]];
-
- [cell setModelDatas:self.morePicCollectionArr];
-
- [self.tableView reloadData];
- } failure:^(NSError *error) {
-
- }];
-
- }
- - (void)setupSubViews
- {
-
- self.navigationController.navigationBar.barStyle = UIStatusBarStyleLightContent;
- contentVCs =[NSMutableArray array];
- self.view.backgroundColor = [UIColor YHColorWithHex:0xFFF3DE];
- self.automaticallyAdjustsScrollViewInsets = NO;
- self.canScroll = YES;
- self.tableView.backgroundColor = [UIColor YHColorWithHex:0xFFF3DE];
- //下移20像素的时候执行
- if([ self.tableView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)])
- {
- if(@available(iOS 11.0, *)) {
- self.tableView.contentInsetAdjustmentBehavior=UIScrollViewContentInsetAdjustmentNever;
-
- }else{// Fallback on earlier versions
-
- }}
- }
- #pragma mark notify
- - (void)changeScrollStatus//改变主视图的状态
- {
- self.canScroll = YES;
- self.contentCell.cellCanScroll = NO;
- }
- #pragma mark UITableView
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- if (self.titleArr.count == 0) {
- return 1;
- }
- return 2;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return 1;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.section == 0) {
- //圆形菜单高度
- CGFloat bannerHeight =KStatusBarHeight+Fitsize(115);
- if (indexPath.row == 0) {
- if (self.morePicCollectionArr==nil||self.morePicCollectionArr.count==0) {
- return .1+bannerHeight;
- }
- NSInteger offHeight=0;
- if (iPhone5) {
- offHeight=10;
- }
- NSInteger Crow=1;
- NSInteger Coff=-1;
- NSInteger CrowItemSum=5;
- Coff=self.morePicCollectionArr.count%CrowItemSum;
- if (Coff!=0) {
- CrowItemSum=4;
- Coff=self.morePicCollectionArr.count%CrowItemSum;
- if (Coff!=0) {
- CrowItemSum=3;
- Coff=self.morePicCollectionArr.count%CrowItemSum;
- if (Coff!=0) {
- CrowItemSum=5;
- Crow++;
- }
- }
- }
- Crow=self.morePicCollectionArr.count/CrowItemSum;
- if (Coff!=0) {
- Crow++;
- }
- NSInteger totalHeight = (SCREEN_WIDTH/4+offHeight)*Crow;
- return totalHeight+bannerHeight;
-
- }
-
- }
- return CGRectGetHeight(self.view.bounds);
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- if (section == 0) {
- return 0;
- }
- return FITSIZE(22);
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
- return 0.1;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- if (self.titleArr.count == 0) {
- return nil;
- }
- self.titleView = [[FSSegmentTitleView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), FITSIZE(22)) titles:self.titleArr delegate:self indicatorType:FSIndicatorTypeEqualTitle];
-
- self.titleView.selectIndex=selectIndex;
- self.titleView.titleSelectColor =[UIColor YHColorWithHex:0xEBB189];
- self.titleView.backgroundColor = [UIColor clearColor];
- return self.titleView;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *FSBaseTopTableViewCellIdentifier = @"FSBaseTopTableViewCellIdentifier";
- if (indexPath.section == 1) {
- _contentCell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
- if (!_contentCell) {
- _contentCell = [[FSBottomTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
-
- for (NSString *title in self.titleArr) {
- FSScrollContentViewController *vc = [[FSScrollContentViewController alloc]init];
- vc.title = title;
- vc.str = title;
- [contentVCs addObject:vc];
- }
-
- _contentCell.viewControllers = contentVCs;
- _contentCell.pageContentView = [[FSPageContentView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NavBarHeight) childVCs:contentVCs parentVC:self delegate:self];
- [_contentCell.contentView addSubview:_contentCell.pageContentView];
-
-
- }
- _contentCell.selectionStyle=UITableViewCellSelectionStyleNone;
- if (contentVCs.count != 0) {
- FSScrollContentViewController *vc =contentVCs[selectIndex];
- vc.model = self.modelArr[selectIndex];
- _tableView.scrollEnabled = YES;
- self.contentCell.pageContentView.contentViewCurrentIndex = selectIndex;
- }
-
- return _contentCell;
- }
- if (indexPath.row == 0) {
- cell = [tableView dequeueReusableCellWithIdentifier:FSBaseTopTableViewCellIdentifier];
- if (!cell) {
- cell = [[FSBaseTopTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:FSBaseTopTableViewCellIdentifier];
- }
- cell.selectionStyle=UITableViewCellSelectionStyleNone;
- cell.backgroundColor =[UIColor YHColorWithHex:0xFFF3DE];
- cell.delegate=self;
- [cell setModelDatas:self.morePicCollectionArr];
- return cell;
- }
- return nil;
- }
- #pragma mark--
- -(void)selectIndex:(NSInteger )endIndex
- {
- FSScrollContentViewController *vc =contentVCs[endIndex];
- selectIndex=endIndex;
- HCHomeChannelModel *models=self.modelArr[endIndex];
- selectModel = models;
- vc.model = models;
- }
- -(void)YHMorePicCollectionCellDidSelectedItem:(NSInteger)index
- {
- LDSuperListModel *model= self.morePicCollectionArr[index];
- //点击大牌商品
- LDSearchCoupleWebViewController *searchCoupleWeb = [[LDSearchCoupleWebViewController alloc] init];
-
- searchCoupleWeb.url = model.url;
- searchCoupleWeb.jsString = model.ios_js_string;
- searchCoupleWeb.name = model.name;
- if ([[ALBBSession sharedInstance] isLogin] && [AccountTool isLogin]) {
- //进入
- [self.navigationController pushViewController:searchCoupleWeb animated:YES];
- }else if (![AccountTool isLogin]) {
- //未登录
- HCLoginViewController *login = [[HCLoginViewController alloc] init];
- [self presentViewController:login animated:YES completion:nil];
- }else if (![[ALBBSession sharedInstance] isLogin]) {
- //淘宝未授权
- ALBBSDK *albbSDK = [ALBBSDK sharedInstance];
- [albbSDK setAppkey:ALBC_APP_KEY];
- [albbSDK setAuthOption:NormalAuth];
-
- [albbSDK auth:self successCallback:^(ALBBSession *session){
- [[NSNotificationCenter defaultCenter] postNotificationName:ChangeTaoBaoAuthor object:nil];
- [self.navigationController pushViewController:searchCoupleWeb animated:YES];
- } failureCallback:^(ALBBSession *session,NSError *error){
- NSLog(@"session == %@,error == %@",session,error);
- }];
- }
- }
- #pragma mark FSSegmentTitleViewDelegate
- - (void)FSContenViewDidEndDecelerating:(FSPageContentView *)contentView startIndex:(NSInteger)startIndex endIndex:(NSInteger)endIndex
- {
- self.titleView.selectIndex = endIndex;
- _tableView.scrollEnabled = YES;//此处其实是监测scrollview滚动,pageView滚动结束主tableview可以滑动,或者通过手势监听或者kvo,这里只是提供一种实现方式
- [self selectIndex:endIndex];
- }
- - (void)FSSegmentTitleView:(FSSegmentTitleView *)titleView startIndex:(NSInteger)startIndex endIndex:(NSInteger)endIndex
- {
- self.contentCell.pageContentView.contentViewCurrentIndex = endIndex;
- [self selectIndex:endIndex];
- }
- - (void)FSContentViewDidScroll:(FSPageContentView *)contentView startIndex:(NSInteger)startIndex endIndex:(NSInteger)endIndex progress:(CGFloat)progress
- {
- _tableView.scrollEnabled = NO;//pageView开始滚动主tableview禁止滑动
- }
- #pragma mark UIScrollView
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView
- {
- if (self.titleArr.count != 0) {
- CGFloat bottomCellOffset = [self.tableView rectForSection:1].origin.y - NavBarHeight;
- if (scrollView.contentOffset.y >= bottomCellOffset) {
- scrollView.contentOffset = CGPointMake(0, bottomCellOffset);
- if (self.canScroll) {
- self.canScroll = NO;
- self.contentCell.cellCanScroll = YES;
- }
- titleLabel.hidden=NO;
- cell.imgv.hidden=YES;
- cell.collectionView.hidden=YES;
-
- }else{
- if (!self.canScroll) {//子视图没到顶部
- scrollView.contentOffset = CGPointMake(0, bottomCellOffset);
- }
-
- titleLabel.hidden=YES;
- cell.imgv.hidden=NO;
- cell.collectionView.hidden=NO;
- }
- }
- }
- #pragma mark LazyLoad
- - (FSBaseTableView *)tableView
- {
- if (!_tableView) {
- _tableView = [[FSBaseTableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.backgroundColor =[UIColor whiteColor];
- _tableView.showsVerticalScrollIndicator=NO;
- _tableView.showsHorizontalScrollIndicator=NO;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.mj_header =[MJRefreshNormalHeader headerWithRefreshingBlock:^{
- [self loadChildViewController];
- }];
-
- titleLabel =[[UILabel alloc]initWithFrame:CGRectMake(FITSIZE(60), 20, SCREEN_WIDTH-FITSIZE(120), NavBarHeight-20)];
- titleLabel.text=@"超级大牌";
- [self.view addSubview:titleLabel];
- titleLabel.textColor=[UIColor YHColorWithHex:0xD98C0D];
- titleLabel.textAlignment=NSTextAlignmentCenter;
- titleLabel.font =[UIFont systemFontOfSize:FITSIZE(16)];
- titleLabel.hidden=YES;
- }
- return _tableView;
- }
- -(void)backAction
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- #pragma mark---分类
- - (void)loadChildViewController {
- [HCCacheHttp get:ChannelList params:nil success:^(id json, BOOL isCache) {
- [self.modelArr removeAllObjects];
- [self.titleArr removeAllObjects];
- NSArray *list = json[@"data"];
- for (int i = 0; i < list.count; i++) {
-
- NSDictionary *dic = list[i];
- HCHomeChannelModel *model = [HCHomeChannelModel yy_modelWithJSON:dic];
- if (i == 0) {
- selectIndex = 0;
- selectModel = model;
- }
- if (_model.Id.integerValue == model.Id.integerValue) {
- selectIndex = i;
- selectModel = model;
- }
- [self.modelArr addObject:model];
- [self.titleArr addObject:model.name];
-
-
- }
- [self.tableView.mj_header endRefreshing];
- [self.tableView reloadData];
-
- } failure:^(NSError *error) {
-
- }];
-
-
- }
- #pragma mark-分类下的列表
- -(void)channellist
- {
- NSString *url =[NSString stringWithFormat:@"%@/api/v2/channel/SuperBrand",BaseURL];
- NSDictionary *dics=@{@"position":@"3",@"category_id":selectModel.Id};
- [HCHttp post:url params:dics success:^(id json) {
-
- } failure:^(NSError *error) {
- }];
- }
- - (NSMutableArray *)modelArr {
- if (!_modelArr) {
- _modelArr = [NSMutableArray array];
- }
- return _modelArr;
- }
- - (NSMutableArray *)titleArr {
- if (!_titleArr) {
- _titleArr = [NSMutableArray array];
- }
- return _titleArr;
- }
- - (NSMutableArray *)vcArray {
- if (!_vcArray) {
- _vcArray = [NSMutableArray array];
- }
- return _vcArray;
- }
- @end
|