123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931 |
- //
- // 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 <AlibcTradeSDK/AlibcTradeSDK.h>
- #import <AlibabaAuthSDK/ALBBSession.h>
- #import <AlibabaAuthSDK/ALBBSDK.h>
- #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<AlibcTradePage> 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
|