// // KBTodayViewController.m // YouHuiProject // // Created by 小花 on 2018/1/17. // Copyright © 2018年 kuxuan. All rights reserved. // #import "KBTodayViewController.h" #import "SDCycleScrollView.h" #import "KBOnePicCell.h" #import "KBCountHeaderView.h" #import "KBMorePicCell.h" #import "KBTodayBannerModel.h" #import "KBChildGoodModel.h" #import "KBMorePicModel.h" #import "KBGoodsInfo.h" #import "KBAdversementCell.h" #import "KBGoodDetailViewController.h" #import "KBGoodListCidViewController.h" #import "KBWebDetailController.h" #import "KBGoodListViewController.h" #import "KBNineNineMainViewController.h" #import "KBMorePicCollectionCell.h" #import "KBMorePicCollectionModel.h" #import "KBGoodCollectionCell.h" #import "KBShareGoodsModel.h" #import "KBShareGoodsViewController.h" #import "KBPrivilegeReferralViewController.h" #import "NSNumber+YHExpanded.h" #import "KBTodayModelCollectionCell.h" #import "KBRankListViewController.h" #import "KBTodayMudleModel.h" #import "KBCategoryListViewContoller.h" #import #import #import #import "KBGetMoneyViewController.h" #import "KBBuyLimitMainController.h" #import "KBTodayReatCollectionCell.h" #import "AdPopModel.h" #import "LDTodayAdView.h" #import "AdJumpManager.h" #import "NewPagedFlowView.h" static NSString *KYHMorePicCollectionCell = @"KYHMorePicCollectionCell"; static NSString *KYHMorePicCell = @"KYHMorePicCell"; static NSString *KYHGoodCollectionCell = @"KYHGoodCollectionCell"; static NSString *KModelCollecionCell = @"modelCollecionCell"; static NSString *KReactCollecionCell = @"ReactCollecionCell"; static NSString *KSectionOne = @"KSectionOne"; static NSString *KSectionTwo = @"KSectionTwo"; static NSString *KSectionThree = @"KSectionThree"; static NSString *KSectionAd = @"KSectionAd"; static CGFloat bannerHeight = 150; @interface KBTodayViewController () < UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, SDCycleScrollViewDelegate, YHMorePicCellDelegate, YHMorePicCollectionCellDelegate, LDTodayModelCollectionCellDelegate, YHCountDownViewDelegate, NewPagedFlowViewDelegate, NewPagedFlowViewDataSource > { NSInteger _page; LDTodayAdView *_adView; NSArray *_adDataArr; } @property (nonatomic, strong) UICollectionView *collectionView; @property (nonatomic, strong) SDCycleScrollView *cycleScrollView; @property (nonatomic, strong) NSArray *bannerList; @property (nonatomic, strong) NSMutableArray *goodsArr; @property (nonatomic, strong) KBMorePicCell *morePicCell; @property (nonatomic, strong) KBMorePicCollectionCell *morePicCollectionCell; @property (nonatomic, strong) NSArray *morePicArr; @property (nonatomic, strong) NSArray *morePicCollectionArr; @property (nonatomic, strong) NSMutableArray *moduleDataArr; @property (nonatomic, strong) KBGoodsInfo *goodsInfo; //商品信息,包括刷新事件 @property (nonatomic, strong) NewPagedFlowView *NewPagedFlowView; /**组头*/ @property (nonatomic, strong) UICollectionReusableView *sectionOne; @property (nonatomic, strong) UICollectionReusableView *sectionThree; @end @implementation KBTodayViewController - (void)viewDidLoad { [super viewDidLoad]; [self configCollectionView]; [self request]; [self.collectionView reloadData]; } - (void)request { [self loadBannerData]; [self loadHotRecomPicCollectionData]; [self loadHotRecomPicData]; [self loadModelCellData]; [self loadCategoryGoodsList]; [self loadAdData]; } - (void)configCollectionView { _page = 1; UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init]; self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH, ChildTableViewHeight+40) collectionViewLayout:flowLayout]; flowLayout.minimumLineSpacing = 5; flowLayout.minimumInteritemSpacing = 1; self.collectionView.showsVerticalScrollIndicator=NO; self.collectionView.showsHorizontalScrollIndicator=NO; [self.collectionView registerClass:[KBMorePicCollectionCell class] forCellWithReuseIdentifier:KYHMorePicCollectionCell]; [self.collectionView registerClass:[KBMorePicCell class] forCellWithReuseIdentifier:KYHMorePicCell]; [self.collectionView registerClass:[KBGoodCollectionCell class] forCellWithReuseIdentifier:KYHGoodCollectionCell]; [self.collectionView registerClass:[KBTodayModelCollectionCell class] forCellWithReuseIdentifier:KModelCollecionCell]; [self.collectionView registerClass:[KBTodayReatCollectionCell class] forCellWithReuseIdentifier:KReactCollecionCell]; [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionOne]; [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionTwo]; [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionThree]; [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionAd]; // self.collectionView.backgroundColor = [UIColor YHColorWithHex:0xf6f6f6]; self.collectionView.backgroundColor = [UIColor clearColor]; self.collectionView.layer.masksToBounds=YES; self.collectionView.delegate = self; self.collectionView.dataSource = self; MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ [self refreshData]; }]; header.activityIndicatorViewStyle=UIActivityIndicatorViewStyleWhite; header.stateLabel.textColor=[UIColor whiteColor]; header.lastUpdatedTimeLabel.hidden=YES; [header setTitle:@"数据正在刷新" forState:MJRefreshStateRefreshing]; // header.lastUpdatedTimeLabel.hidden = YES; // header.stateLabel.hidden = YES; //正在刷新的图片 // NSArray *imgArr = @[[UIImage imageNamed:@"ant1"],[UIImage imageNamed:@"ant2"]]; // [header setImages:imgArr duration:0.3 forState:MJRefreshStateRefreshing]; // [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStateWillRefresh]; // [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStatePulling]; self.collectionView.mj_header = header; self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{ [self loadMoreData]; }]; [self.collectionView.mj_footer beginRefreshing]; if (@available(iOS 11.0, *)) { self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;//UIScrollView也适用 }else { self.automaticallyAdjustsScrollViewInsets = NO; } [self.view addSubview:self.collectionView]; // CGFloat height = (bannerHeight/375.f)*SCREEN_WIDTH; // CGRect rect = CGRectMake(FITSIZE(10), 3, SCREEN_WIDTH-FITSIZE(20), height); // // self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:rect delegate:self placeholderImage:nil]; // self.cycleScrollView.backgroundColor=[UIColor clearColor]; // self.cycleScrollView.currentPageDotImage = [UIImage imageNamed:@"page_sel"]; // self.cycleScrollView.pageDotImage = [UIImage imageNamed:@"page_nor"]; // // self.cycleScrollView.layer.masksToBounds=YES; // self.cycleScrollView.clipsToBounds = YES; // self.cycleScrollView.layer.shadowColor = [UIColor YHColorWithHex:0x000000].CGColor; // self.cycleScrollView.layer.shadowOffset = CGSizeMake(3,3); // self.cycleScrollView.layer.shadowOpacity = 0.2f; // self.cycleScrollView.layer.shadowRadius = 3; // self.cycleScrollView.layer.cornerRadius=5; // self.cycleScrollView.autoScrollTimeInterval=3; // self.cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleToFill; self.NewPagedFlowView = [[NewPagedFlowView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH * bannerHeight / 375)]; self.NewPagedFlowView.backgroundColor = [UIColor clearColor]; self.NewPagedFlowView.delegate = self; self.NewPagedFlowView.dataSource = self; self.NewPagedFlowView.minimumPageAlpha = 0.1; self.NewPagedFlowView.isCarousel = YES; self.NewPagedFlowView.orientation = NewPagedFlowViewOrientationHorizontal; self.NewPagedFlowView.isOpenAutoScroll = YES; self.NewPagedFlowView.layer.shadowOffset = CGSizeMake(2, 5); self.NewPagedFlowView.layer.shadowOpacity = 0.3; self.NewPagedFlowView.layer.shadowColor = [UIColor blackColor].CGColor; } - (void)loadAdData { NSString *url = [NSString stringWithFormat:@"%@/api/v2/adv/advByType",BaseURL]; NSDictionary *para = @{@"adv_type":@"1"}; [KBHttp get:url params:para success:^(id json) { _adDataArr = [NSArray yy_modelArrayWithClass:[AdPopModel class] json:json[@"data"]]; if (_adDataArr.count > 0) { [self creatAdView:_adDataArr]; } [self.collectionView reloadData]; } failure:^(NSError *error) { }]; } - (void)creatAdView:(NSArray *)list { // LDTodayAdView *adView = [[LDTodayAdView alloc] initWithFrame:CGRectMake(Fitsize(10), Fitsize(3), SCREEN_WIDTH-Fitsize(20), (SCREEN_WIDTH-Fitsize(20))*200/750)]; LDTodayAdView *adView = [[LDTodayAdView alloc] initWithFrame:CGRectMake(Fitsize(10), 5, SCREEN_WIDTH-Fitsize(20), (SCREEN_WIDTH-Fitsize(20))*200/750)]; _adView.tag=2002; _adView = adView; _adView.model = list.firstObject; adView.tapAdBlock = ^{ [MobClick event:AdvClick label:@"1"]; [AdJumpManager jumpToPageWithModel:list.firstObject ParentViewControll:self]; }; } - (void)loadBannerData { [KBCacheHttp get:Banner_list params:nil success:^(id json, BOOL isCache) { self.bannerList = [NSArray yy_modelArrayWithClass:[KBTodayBannerModel class] json:json[@"data"]]; [self creatCycleScrollView]; } failure:^(NSError *error) { }]; } - (void)creatCycleScrollView { NSMutableArray *imgArr = [NSMutableArray array]; for (KBTodayBannerModel *model in self.bannerList) { [imgArr addObject:model.photo]; } // self.cycleScrollView.imageURLStringsGroup = imgArr; [self.NewPagedFlowView reloadData]; } /** 加载下部商品列表 */ - (void)loadCategoryGoodsList { NSDictionary *para = @{@"sort":@"1", @"page":@(_page), @"category_id":self.model.Id, @"stype":@"0"}; [KBCacheHttp post:StocklistByCategoryId params:para success:^(id json, BOOL isCache) { if ([self.collectionView.mj_header isRefreshing]) [self.goodsArr removeAllObjects]; //清空缓存数据,展示真正的数据(如果page是1,且不是缓存数据,说明是真正的数据) if (_page == 1 && !isCache) [self.goodsArr removeAllObjects]; self.goodsInfo = [KBGoodsInfo yy_modelWithJSON:json]; NSArray *list = [NSArray yy_modelArrayWithClass:[KBChildGoodModel class] json:json[@"data"]]; [self noMoreDataWithArray:list]; [self.goodsArr addObjectsFromArray:list]; [self.collectionView reloadData]; } failure:^(NSError *error) { [self endRefreshing]; [self.collectionView.mj_footer endRefreshing]; }]; } - (void)noMoreDataWithArray:(NSArray *)array { if (array.count <= 0) { [self.collectionView.mj_footer endRefreshingWithNoMoreData]; }else { [self.collectionView.mj_footer endRefreshing]; } } - (void)endRefreshing { [self.collectionView.mj_header endRefreshing]; } - (void)refreshData { _page = 1; [self loadBannerData]; [self loadModelCellData]; [self loadHotRecomPicData]; [self loadHotRecomPicCollectionData]; [self loadCategoryGoodsList]; [self loadAdData]; } /** 上拉加载 */ - (void)loadMoreData { _page++; [self loadCategoryGoodsList]; } /** 多图推荐 */ - (void)loadHotRecomPicData { [KBCacheHttp get:Goldgroups params:nil success:^(id json, BOOL isCache) { self.morePicArr = [NSArray yy_modelArrayWithClass:[KBMorePicModel class] json:json[@"data"]]; if (self.morePicArr.count==0) { [self.collectionView reloadData]; } // [self.morePicCell setModelDatas:self.morePicArr]; [self.collectionView reloadData]; } failure:^(NSError *error) { }]; } /** 加载菜单栏目 */ - (void)loadHotRecomPicCollectionData { [KBCacheHttp get:GoldCollectiongroups params:nil success:^(id json, BOOL isCache) { self.morePicCollectionArr = [NSArray yy_modelArrayWithClass:[KBMorePicCollectionModel class] json:json[@"data"]]; [self.morePicCollectionCell setModelDatas:self.morePicCollectionArr]; [self.collectionView reloadData]; } failure:^(NSError *error) { }]; } /** 加载分类模块数据 */ - (void)loadModelCellData { NSString *url = [NSString stringWithFormat:@"%@/api/v2/channel/advFourList",BaseURL]; [KBCacheHttp post:url params:@{@"platform":@"2"} success:^(id json, BOOL isCache) { NSArray *list = [NSArray yy_modelArrayWithClass:[KBTodayMudleModel class] json:json[@"list"]]; if (list.count > 0) { [self countDownViewSetCount:list.firstObject]; } [self.moduleDataArr removeAllObjects]; [self.moduleDataArr addObjectsFromArray:list]; [self.collectionView reloadData]; [self endRefreshing]; } failure:^(NSError *error) { [self endRefreshing]; }]; } - (void)countDownViewSetCount:(KBTodayMudleModel *)model { NSString *endTime = [NSString stringWithFormat:@"%@000",model.remainTime]; [[KBCountDownView shareInstace] setEndTimer:endTime]; } #pragma mark ==== #pragma mark NewPagedFlowView Delegate - (CGSize)sizeForPageInFlowView:(NewPagedFlowView *)flowView { return CGSizeMake(SCREEN_WIDTH - 40, (SCREEN_WIDTH - 40) * 150 / 375); } - (void)didSelectCell:(UIView *)subView withSubViewIndex:(NSInteger)subIndex { KBTodayBannerModel *model = self.bannerList[subIndex]; if (model.url.length > 0) { //活动页 //type为2直接打开淘宝,无需访问中间网页 if ([model.type isEqualToString:@"2"]) { [self jumpToTaobaoWithUrl:model.url]; }else{ KBWebDetailController *adWeb = [[KBWebDetailController alloc] init]; adWeb.url = model.url; [self.navigationController pushViewController:adWeb animated:YES]; } }else { //列表页 KBGoodListViewController *list = [[KBGoodListViewController alloc] init]; list.cate_id = model.group_id; list.name = model.note; [self.navigationController pushViewController:list animated:YES]; } [MobClick event:home_banner label:model.photo]; } #pragma mark NewPagedFlowView Datasource - (NSInteger)numberOfPagesInFlowView:(NewPagedFlowView *)flowView { return self.bannerList.count; } - (PGIndexBannerSubiew *)flowView:(NewPagedFlowView *)flowView cellForPageAtIndex:(NSInteger)index{ PGIndexBannerSubiew *bannerView = [flowView dequeueReusableCell]; if (!bannerView) { bannerView = [[PGIndexBannerSubiew alloc] init]; bannerView.tag = index; bannerView.layer.cornerRadius = 4; bannerView.layer.masksToBounds = YES; } if (self.bannerList.count > 0 && self.bannerList.count>index) { KBTodayBannerModel *model = self.bannerList[index]; //在这里下载网络图片 [bannerView.mainImageView sd_setImageWithURL:[NSURL URLWithString:model.photo] placeholderImage:[UIImage imageNamed:@""]]; } return bannerView; } #pragma mark ------ YHCountDownViewDelegate ------- - (void)countViewTimeOutAction { [self.collectionView.mj_header beginRefreshing]; } #pragma mark ====================== YHMorePicCellDelegate========== /** 点击推荐位多图 */ - (void)YHMorePicCellDidSelectedItem:(NSInteger)index { KBMorePicModel *model = self.morePicArr[index]; if (model.url.length > 0) { //活动页 //type为2直接打开淘宝,无需访问中间网页 if ([model.jump_type isEqualToString:@"2"]) { [self jumpToTaobaoWithUrl:model.url]; }else{ KBWebDetailController *adWeb = [[KBWebDetailController alloc] init]; adWeb.url = model.url; [self.navigationController pushViewController:adWeb animated:YES]; } }else { //列表页 KBGoodListViewController *list = [[KBGoodListViewController alloc] init]; list.cate_id = model.Id; list.name = model.name; [self.navigationController pushViewController:list animated:YES]; } [MobClick event:home_recommend label:model.name]; } #pragma mark ====================== YHMorePicCollectionCellDelegate========== - (void)YHMorePicCollectionCellDidSelectedItem:(NSInteger)index{ KBMorePicCollectionModel *model = self.morePicCollectionArr[index]; if (model.url.length > 0) { //活动页 //type为2直接打开淘宝,无需访问中间网页 if ([model.jump_type isEqualToString:@"2"]) { [self jumpToTaobaoWithUrl:model.url]; }else{ KBWebDetailController *adWeb = [[KBWebDetailController alloc] init]; adWeb.url = model.url; [self.navigationController pushViewController:adWeb animated:YES]; } }else { KBGoodListViewController *list = [[KBGoodListViewController alloc] init]; list.cate_id = model.Id; list.name = model.name; [self.navigationController pushViewController:list animated:YES]; } [MobClick event:Home_Items label:model.name]; } #pragma mark ============ SDCycleScrollViewDelegate ========== - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index { KBTodayBannerModel *model = self.bannerList[index]; if (model.url.length > 0) { //活动页 //type为2直接打开淘宝,无需访问中间网页 if ([model.type isEqualToString:@"2"]) { [self jumpToTaobaoWithUrl:model.url]; }else{ KBWebDetailController *adWeb = [[KBWebDetailController alloc] init]; adWeb.url = model.url; [self.navigationController pushViewController:adWeb animated:YES]; } }else { //列表页 KBGoodListViewController *list = [[KBGoodListViewController alloc] init]; list.cate_id = model.group_id; list.name = model.note; [self.navigationController pushViewController:list animated:YES]; } [MobClick event:home_banner label:model.photo]; } #pragma mark ------- LDTodayModelCollectionCellDelegate ----- - (void)modelCollectionCellMoreButtonClick:(KBTodayModelCollectionCell *)cell{ KBTodayMudleModel *model = cell.model; if ([model.type isEqualToString:@"1"]) { KBBuyLimitMainController *buyLimit = [[KBBuyLimitMainController alloc] init]; [self.navigationController pushViewController:buyLimit animated:YES]; }else if ([model.type isEqualToString:@"2"]){ KBGoodListViewController *rankList = [[KBGoodListViewController alloc] init]; rankList.name = model.name; rankList.flag = 2; rankList.cate_id = model.Id; [self.navigationController pushViewController:rankList animated:YES]; }else { //列表页 KBGoodListViewController *list = [[KBGoodListViewController alloc] init]; list.cate_id = model.Id; list.name = model.name; [self.navigationController pushViewController:list animated:YES]; } [MobClick event:TodayClickTop label:model.name]; } #pragma mark ============ UICollectionView Delegate && DataSource ========== - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { if (section == 0 ) { return 1; }else if (section == 1){ return self.morePicArr.count; }else if (section == 2){ return self.moduleDataArr.count; }else if(section == 3){ return self.goodsArr.count; } return 0; } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 4; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { if (self.morePicCollectionArr==nil||self.morePicCollectionArr.count==0) { return CGSizeMake(SCREEN_WIDTH, .1); } 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++; } CGFloat totalHeight = (SCREEN_WIDTH/4+offHeight)*Crow; return CGSizeMake(SCREEN_WIDTH, totalHeight); } if (indexPath.section == 1) { // if (!self.morePicArr.count||self.morePicArr.count==0) { // return CGSizeMake(SCREEN_WIDTH, .1); // } // CGFloat leftWidth = SCREEN_WIDTH*0.37; // CGFloat leftHeight = leftWidth*19/14; // return CGSizeMake(SCREEN_WIDTH, leftHeight); CGFloat width = (SCREEN_WIDTH-22)/2; CGSize size = CGSizeMake(width, width*83/170); return size; }else if (indexPath.section == 2){ return CGSizeMake(SCREEN_WIDTH-FITSIZE(20), Fitsize(228)); } else if (indexPath.section == 3) { CGFloat width = (SCREEN_WIDTH)/2; CGFloat height = width + 102; return CGSizeMake(width-FITSIZE(12.5f), height); } return CGSizeZero; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section { if (section == 0) { CGFloat height = (bannerHeight/375.f)*SCREEN_WIDTH; return CGSizeMake(SCREEN_WIDTH, height); }else if (section == 1){ return CGSizeMake(SCREEN_WIDTH,5); }else if (section == 2){ CGFloat height = _adDataArr.count>0?((SCREEN_WIDTH-Fitsize(20))*200/750+10):5; return CGSizeMake(SCREEN_WIDTH,height); }else { return CGSizeMake(SCREEN_WIDTH, FITSIZE(40)); } } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section { return CGSizeMake(0, 0); } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section==0) { self.morePicCollectionCell = [collectionView dequeueReusableCellWithReuseIdentifier:KYHMorePicCollectionCell forIndexPath:indexPath]; self.morePicCollectionCell.backgroundColor=[UIColor clearColor]; self.morePicCollectionCell.delegate = self; [self.morePicCollectionCell setModelDatas:self.morePicCollectionArr]; return self.morePicCollectionCell; } if (indexPath.section == 1) { // self.morePicCell = [collectionView dequeueReusableCellWithReuseIdentifier:KYHMorePicCell forIndexPath:indexPath]; // self.morePicCell.delegate = self; // [self.morePicCell setModelDatas:self.morePicArr]; KBTodayReatCollectionCell *reactCell = [self.collectionView dequeueReusableCellWithReuseIdentifier:KReactCollecionCell forIndexPath:indexPath]; KBMorePicModel *model = self.morePicArr[indexPath.row]; reactCell.model = model; return reactCell; }else if (indexPath.section == 2){//限时抢购 KBTodayModelCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KModelCollecionCell forIndexPath:indexPath]; cell.delegate = self; cell.indexPath = indexPath; cell.backgroundColor=[UIColor clearColor]; KBTodayMudleModel *model = self.moduleDataArr[indexPath.row]; cell.model = model; if (indexPath.row == 0) { KBCountDownView *countdown = [KBCountDownView shareInstace]; countdown.y = Fitsize(15); countdown.x = Fitsize(132); countdown.delegate = self; [cell addSubview:countdown]; cell.desLabel.hidden = YES; }else { cell.desLabel.hidden = NO; } return cell; } else if(indexPath.section == 3){ KBChildGoodModel *model = self.goodsArr[indexPath.item]; KBGoodCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KYHGoodCollectionCell forIndexPath:indexPath]; cell.model = model; return cell; } return nil; } - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 0) { self.sectionOne = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionOne forIndexPath:indexPath]; [self.sectionOne addSubview:self.NewPagedFlowView]; return self.sectionOne; } if (indexPath.section == 1) { UICollectionReusableView *sectionTwo = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionTwo forIndexPath:indexPath]; return sectionTwo; } if (indexPath.section == 2) { UICollectionReusableView *sectionTwo = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionAd forIndexPath:indexPath]; UIView *view=[sectionTwo viewWithTag:2002]; if (view) { [view removeFromSuperview]; } [sectionTwo addSubview:_adView]; return sectionTwo; } if (indexPath.section == 3) { self.sectionThree = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionThree forIndexPath:indexPath]; UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, Fitsize(65), Fitsize(40))]; title.font = [UIFont systemFontOfSize:Fitsize(17)];//[UIColor homeRedColor] title.centerX = SCREEN_WIDTH/2; title.text = @"精选好物"; [title sizeToFit]; title.textColor =[UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0x53F3FD] toColor:[UIColor YHColorWithHex:0x726BFF] withWidth:title.width]; UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(title.left-20, 0, Fitsize(13), Fitsize(15))]; icon.centerY = title.centerY; icon.image = [UIImage imageNamed:@"hotRecom_left"]; UIImageView *icon2 = [[UIImageView alloc] initWithFrame:CGRectMake(title.right+5, 0, Fitsize(13), Fitsize(15))]; icon2.centerY = title.centerY; icon2.image = [UIImage imageNamed:@"hotRecom_right"]; [self.sectionThree addSubview:title]; [self.sectionThree addSubview:icon]; [self.sectionThree addSubview:icon2]; // UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, Fitsize(40))]; // title.text = @"精选好物"; // title.textColor = [UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0x47FFDA] toColor:[UIColor YHColorWithHex:0x38D4FB] withWidth:SCREEN_WIDTH]; // title.font = [UIFont systemFontOfSize:Fitsize(19)]; // [title sizeToFit]; // title.centerX = SCREEN_WIDTH/2+Fitsize(10); // title.centerY = Fitsize(20); // [self.sectionThree addSubview:title]; // // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(title.x-Fitsize(25), 0, Fitsize(23), FITSIZE(21))]; // imageView.centerY = Fitsize(20); // imageView.image = [UIImage imageNamed:@"good_gs"]; // [self.sectionThree addSubview:imageView]; return self.sectionThree; } return nil; } #pragma mark -内边距 - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { if (section == 1) { return UIEdgeInsetsMake(0, 10, 0, 10); }else if(section==3 ){ return UIEdgeInsetsMake(0, 10, 0, 10); }else { return UIEdgeInsetsMake(0, 0, 0, 0); } } #pragma mark -行间距 - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { if (section == 1) { return 2; }else { return 5; } } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 1) { KBMorePicModel *model = self.morePicArr[indexPath.row]; if (model.url.length > 0) { //活动页 //type为2直接打开淘宝,无需访问中间网页 if ([model.jump_type isEqualToString:@"2"]) { [self jumpToTaobaoWithUrl:model.url]; }else{ KBWebDetailController *adWeb = [[KBWebDetailController alloc] init]; adWeb.url = model.url; [self.navigationController pushViewController:adWeb animated:YES]; } }else { //列表页 KBCategoryListViewContoller *list = [[KBCategoryListViewContoller alloc] init]; list.cate_id = model.Id; list.name = model.name; list.material_id = model.material_id; [self.navigationController pushViewController:list animated:YES]; } [MobClick event:home_recommend label:model.name]; } if (indexPath.section == 3) { KBChildGoodModel *model = self.goodsArr[indexPath.row]; KBEventModel *evevtModel = [[KBEventModel alloc] initWithOrigin:model.origin category_id:self.model.Id source:homeAction]; KBGoodDetailViewController *detail = [[KBGoodDetailViewController alloc] init]; detail.eventModel = evevtModel; DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model]; detail.requestModel = requestModel; [self.navigationController pushViewController:detail animated:YES]; [MobClick event:home_hot]; } } #pragma mark ------ #pragma mark - scrollView - (void)scrollViewDidScroll:(UIScrollView *)scrollView { //scrollView已经有拖拽手势,直接拿到scrollView的拖拽手势 UIPanGestureRecognizer *pan = scrollView.panGestureRecognizer; //获取到拖拽的速度 >0 向下拖动 <0 向上拖动 CGFloat velocity = [pan velocityInView:scrollView].y; if (velocity <- 10) { //向上拖动,隐藏导航栏 self.collectionView.height = ChildTableViewHeight+NavBarHeight-KStatusBarHeight; }else if (velocity > 10) { //向下拖动,显示导航栏 self.collectionView.height = ChildTableViewHeight; }else if(velocity == 0){ //停止拖拽 } NSNotification *noti = [[NSNotification alloc] initWithName:ScrollDirectorNoti object:nil userInfo:@{@"director":@(velocity)}]; [[NSNotificationCenter defaultCenter] postNotification:noti]; } #pragma mark ------ - (void)jumpToTaobaoWithUrl:(NSString *)url { id page = [AlibcTradePageFactory page:url]; //淘客信息 AlibcTradeTaokeParams *taoKeParams=[[AlibcTradeTaokeParams alloc] init]; taoKeParams.pid= ALTK_PID; //打开方式 AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init]; showParam.openType = AlibcOpenTypeNative; [[AlibcTradeSDK sharedInstance].tradeService show:self.parentViewController page:page showParams:showParam taoKeParams:taoKeParams trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) { } tradeProcessFailedCallback:^(NSError * _Nullable error) { }]; } #pragma mark ===================== layezer ============== - (NSArray *)goodsArr { if (!_goodsArr) { _goodsArr = [NSMutableArray array]; } return _goodsArr; } - (NSMutableArray *)moduleDataArr { if (!_moduleDataArr) { _moduleDataArr = [NSMutableArray array]; } return _moduleDataArr; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end