//
|
// recommendView.m
|
// BuWanVideo2.0
|
//
|
// Created by weikou on 16/8/1.
|
// Copyright © 2016年 com.yeshi.buwansheque.ios. All rights reserved.
|
//
|
|
#import "recommendView.h"
|
#import "WeiKouHeader.h"
|
|
#import "recommentCollectionViewCell.h"
|
#import "StartCollectionViewCell.h"
|
#import "shufflingCollectionReusableView.h"
|
#import "HeaderCollectionReusableView.h"
|
#import "FooterCollectionReusableView.h"
|
#import "ADCollectionReusableView.h"
|
#import "GoogleAdCollectionReusableView.h"
|
|
#import "XYRVideoInfoModel.h"
|
#import "XYRDetailViewController.h"
|
#import "SubregionDetailViewController.h"
|
#import "FuLiSheViewController.h"
|
|
#import "OnlySpecialController.h"//专辑视图
|
|
#import "StarsController.h"//明星合集
|
#import "IndividualStarController.h"//明星详情页
|
|
#import "LXAlertView.h"//弹窗视图
|
//#import "GDTNativeAd.h"//广点通原生广告
|
#import "YTHNetdata.h"
|
#import "UIImage+GIF.h"
|
#import "AdCollectionViewCell.h"
|
#import "GDTNativeExpressAd.h"
|
#import "GDTNativeExpressAdView.h"
|
|
#define collectTag 270
|
|
@interface recommendView()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,BSKImagesPageViewViewDelegate,UIScrollViewDelegate,GDTNativeExpressAdDelegete>{
|
|
// UICollectionView *_recommentCollectionView;//覆盖整个View的瀑布流
|
BSKImagesPageView *_cycleScrollView;//头部的推荐轮播图
|
WeiKouAdView *_adView;//头部小广告
|
|
BOOL googleNoAdToShow;//当这个变量为YES时,说明谷歌广告没有资源
|
|
//广点通原生广告
|
// GDTNativeAd *_nativeAd; //原生广告实例
|
// NSArray *nativeArray;//存储请求下来的原生广告信息
|
NSString *_type_id;
|
NSString *_type_title;
|
NSInteger maintypeNumber;//种类的位置
|
NSInteger typeNumber;//细分类
|
BOOL _isrefresh;
|
|
}
|
|
@property (nonatomic , strong) NSMutableArray *dataAdverti;//顶部广告数据
|
|
@property (nonatomic , strong) NSMutableArray *addrssForshuffling;//装载轮播图的地址
|
|
@property (nonatomic , strong) NSMutableArray *TitleForshuffling;//装载轮播图的标题
|
|
@property(nonatomic, strong) UIView *nativeAdView;//装载谷歌广告的视图
|
|
@property(nonatomic,strong) NSMutableArray *dataStar;//明星
|
|
@property (nonatomic, strong) HMSegmentedControl *vidioGmentControl;
|
|
@property (nonatomic, strong)UIScrollView *scrollView;
|
@property (nonatomic ,strong)NSMutableArray *collectArray;
|
|
@property (nonatomic, strong)NSMutableArray *classArray;
|
@property (weak, nonatomic) IBOutlet UISegmentedControl *segView;
|
@property (nonatomic , strong) NSString *Species;//种类
|
@property (nonatomic , strong) NSMutableArray *SpeciesAry;//种类
|
@property (nonatomic , strong) NSMutableDictionary *dataDic;//种类下的数据源
|
|
@property (nonatomic , strong) NSMutableArray *allDataSourece;//所有数据数组
|
@property (nonatomic , strong) NoNetworkView *noNetworkView;
|
|
@property (nonatomic, strong) UIViewController *adViewController;
|
@property (nonatomic, strong) NSArray *expressAdViews;
|
@property (nonatomic, strong) GDTNativeExpressAd *nativeExpressAd;
|
@property (nonatomic, strong) NSArray *secExpressAdViews;
|
@property (nonatomic, strong) GDTNativeExpressAd *secNativeExpressAd;
|
@property (nonatomic, strong) NSArray *thiExpressAdViews;
|
@property (nonatomic, strong) GDTNativeExpressAd *thiNativeExpressAd;
|
@property (nonatomic, strong) NSArray *clSecExpressAdViews;
|
@property (nonatomic, strong) GDTNativeExpressAd *clSecNativeExpressAd;
|
@property (nonatomic, strong) NSArray *clThiExpressAdViews;
|
@property (nonatomic, strong) GDTNativeExpressAd *clThiNativeExpressAd;
|
@end
|
|
@implementation recommendView
|
|
- (instancetype)initWithFrame:(CGRect)frame{
|
self = [super initWithFrame:frame];
|
if (self) {
|
self.classArray = @[].mutableCopy;
|
self.collectArray = @[].mutableCopy;
|
// maintypeNumber = 0;
|
self.allDataSourece = @[].mutableCopy;
|
self.dataDic = @{}.mutableCopy;
|
|
[self NetworkMonitoring];
|
[self loadDataFromFile];
|
UIViewController *controller = [self viewController];
|
controller.automaticallyAdjustsScrollViewInsets = NO;
|
self.adViewController = controller;
|
|
}
|
|
return self;
|
}
|
//- (void)viewWillLayoutSubviews{
|
// [self viewWillLayoutSubviews];
|
// [self.collectionView.collectionViewLayout invalidateLayout];
|
//}
|
- (void)NetworkMonitoring{
|
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
selector:@selector(reachabilityChang:)
|
name:AFNetworkingReachabilityDidChangeNotification
|
object:nil];
|
}
|
- (void) reachabilityChang: (NSNotification*)note {
|
switch ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus) {
|
case AFNetworkReachabilityStatusNotReachable:{//无网
|
_noNetworkView.hidden = NO;
|
[self bringSubviewToFront:_noNetworkView];
|
}
|
break;
|
case AFNetworkReachabilityStatusReachableViaWWAN:{//万维网
|
// [self loadDataFromFile];
|
_noNetworkView.hidden = YES;
|
|
}
|
break;
|
case AFNetworkReachabilityStatusReachableViaWiFi:{// 使用WiFi网络
|
// [self loadDataFromFile];
|
_noNetworkView.hidden = YES;
|
|
}
|
break;
|
case AFNetworkReachabilityStatusUnknown:{// 当前网络未知
|
|
}
|
break;
|
}
|
}
|
//create
|
- (void)createSegment{
|
NSMutableArray *array = @[].mutableCopy;
|
for (NSInteger index = 0; index <self.classArray.count; index ++) {
|
NSDictionary *dic = self.classArray[index];
|
[array addObject:dic[@"Name"]];
|
}
|
NSLog(@"%@",array);
|
self.vidioGmentControl = [[HMSegmentedControl alloc]initWithSectionTitles:array];
|
[self.vidioGmentControl setFrame:CGRectMake(0, 0, KScreenW, 40)];
|
|
if (KIsiPhoneX) {
|
[self.vidioGmentControl setFrame:CGRectMake(0, 0, KScreenW, 40)];
|
}
|
self.vidioGmentControl.selectionIndicatorHeight = 2.0f;
|
self.vidioGmentControl.backgroundColor = kGlobalMainColor;
|
self.vidioGmentControl.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor],NSFontAttributeName :[UIFont systemFontOfSize:15]};
|
self.vidioGmentControl.selectedTitleTextAttributes=@{NSForegroundColorAttributeName : kGlobalYellowColor,NSFontAttributeName :[UIFont systemFontOfSize:15]};
|
self.vidioGmentControl.selectionIndicatorColor = kGlobalYellowColor;
|
self.vidioGmentControl.selectionStyle = HMSegmentedControlSelectionStyleTextWidthStripe;
|
self.vidioGmentControl.selectedSegmentIndex = HMSegmentedControlNoSegment;
|
self.vidioGmentControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
|
self.vidioGmentControl.selectedSegmentIndex=0;
|
self.vidioGmentControl.shouldAnimateUserSelection = YES;
|
|
__weak typeof(self) weakSelf = self;
|
[self.vidioGmentControl setIndexChangeBlock:^(NSInteger index) {
|
[weakSelf.scrollView scrollRectToVisible:CGRectMake(KScreenW * index, 0, KScreenW, self.frame.size.height - 40) animated:YES];
|
_type_title = self.classArray[index][@"Name"];
|
_type_id = self.classArray[index][@"Id"];
|
[weakSelf loadAd];
|
// NSLog(@"<- %@ ->",_type_id);
|
maintypeNumber = index;
|
// NSArray * dataHomeType = weakSelf.allDataSourece[maintypeNumber][@"shopping"];
|
// if (dataHomeType.count == 0) {
|
[weakSelf loadNewData];
|
// }
|
}];
|
[self addSubview:self.vidioGmentControl];
|
}
|
//加载数据
|
-(void)loadDataFromFile{
|
[[YTHNetInterface startInterface]cancelAll];
|
|
[[YTHNetInterface startInterface] getVideoClassWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
NSDictionary *dic = (NSDictionary *)result;
|
|
if (!_classArray) {
|
_classArray = [[NSMutableArray alloc ] initWithCapacity:0];
|
}
|
[_classArray removeAllObjects];
|
NSLog(@"%@",dic);
|
NSArray *ar = [[dic objectForKey:@"Data"] objectForKey:@"data"];
|
for (int i = 0; i<ar.count; i++) {
|
[_classArray addObject:[ar objectAtIndex:i]];
|
NSLog(@"%@%d id= %@",[ar objectAtIndex:i][@"Name"],i,[ar objectAtIndex:i][@"Id"]);
|
}
|
NSLog(@"*****%@****",ar);
|
NSLog(@"、、、、%@、、、、",_classArray);
|
// NSData *data = [NSKeyedArchiver archivedDataWithRootObject:_classArray];
|
// [data writeToFile:CHANNELfILE atomically:YES];
|
//刷新collectionView视图
|
// [_collview reloadData];
|
if (self.allDataSourece.count == 0) {
|
for (NSInteger index = 0; index < _classArray.count; index ++) {
|
NSDictionary * dic = @{};
|
[self.allDataSourece addObject:dic];
|
}
|
}
|
[self createSegment];
|
[self addScrollView];
|
}else{
|
if ([error compare:@"似乎已断开与互联网的连接。"] == 0) {
|
if (_delegate && [_delegate respondsToSelector:@selector(notHaveNetWork:)]) {
|
[_delegate notHaveNetWork:self];
|
}
|
}
|
}
|
}];
|
|
}
|
|
|
/**
|
* 加载新数据
|
*/
|
-(void)loadNewData{
|
NSLog(@"%ld",(long)maintypeNumber);
|
NSLog(@"%@",_type_id);
|
[[YTHNetInterface startInterface]cancelAll];
|
//获取轮播图的数据
|
[self getHomeAd];
|
//小广告推广视图
|
// [self SpreadRequest];
|
|
//获取推荐分类
|
// [self getHomeType];
|
// UICollectionView *collectview = [self viewWithTag:900 + SpeciesNumber];
|
// [collectview reloadData];
|
}
|
|
/**
|
* 获取存储在沙盒中的数据
|
*/
|
-(void)loadOldData{
|
//获取旧的轮播图数据
|
// NSFileManager *fileManager = [NSFileManager defaultManager];
|
// if ([fileManager fileExistsAtPath:ADVERTISEFILE]){
|
// _dataAdverti=[NSKeyedUnarchiver unarchiveObjectWithData:[NSData dataWithContentsOfFile:ADVERTISEFILE]];
|
// [self addSliderView];
|
// }
|
// //获取旧的推荐分类数据
|
// if ([fileManager fileExistsAtPath:HOMETYPEFILE]){
|
// _dataHomeType = [NSKeyedUnarchiver unarchiveObjectWithData:[NSData dataWithContentsOfFile:HOMETYPEFILE]];
|
// }
|
// //判断本地是否有明星数据,如果有数据就进行预加载
|
// if ([fileManager fileExistsAtPath:DISCOVERSTAR]){
|
// _dataStar=[NSKeyedUnarchiver unarchiveObjectWithData:[NSData dataWithContentsOfFile:DISCOVERSTAR]];
|
// }
|
//加载新数据
|
[self loadNewData];
|
}
|
|
/**
|
* 获取轮播图的数据
|
*/
|
-(void)getHomeAd{
|
NSLog(@"%@",_type_id);
|
if ([_type_id integerValue] == 309 || [_type_id integerValue] == 310) {
|
[[YTHNetInterface startInterface] getHomeAdWithUid:[YTHsharedManger startManger].Uid vtid:_type_id withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
[self SpreadRequest];
|
[self getHomeType];
|
|
if (isSuccessful) {
|
NSDictionary *dic = (NSDictionary *)result;
|
if (!_dataAdverti) {
|
_dataAdverti = [[NSMutableArray alloc] initWithCapacity:0];
|
}
|
_dataAdverti = [[dic objectForKey:@"Data"] objectForKey:@"data"];
|
|
//存储获取到的数据
|
// NSData *data = [NSKeyedArchiver archivedDataWithRootObject:_dataAdverti];
|
// [data writeToFile:ADVERTISEFILE atomically:YES];
|
// [_recommentCollectionView reloadData];
|
NSLog(@"<------- %@ --------->",_dataAdverti);
|
//结束刷新
|
// UICollectionView *collectview = [self viewWithTag:collectTag + maintypeNumber];
|
|
UICollectionView *collectview = self.collectArray[maintypeNumber];
|
|
[collectview.mj_header endRefreshing];
|
|
// [self collectLoadNewData];
|
// NSDictionary *datasourceDic = @{@"ad":_dataAdverti};
|
[self.dataDic setValue:_dataAdverti forKey:@"ad"];
|
[self.allDataSourece removeObjectAtIndex:maintypeNumber];
|
[self.allDataSourece insertObject:self.dataDic atIndex:maintypeNumber];
|
[self addSliderView];
|
|
}else{
|
//提示网络不稳定
|
// UICollectionView *collectview = [self viewWithTag:collectTag + maintypeNumber];
|
UICollectionView *collectview = self.collectArray[maintypeNumber];
|
// [self addSliderView];
|
|
[collectview.mj_header endRefreshing];
|
}
|
}];
|
}else{
|
//getRecommendCategoryVideoBanne
|
[[YTHNetInterface startInterface] getRecommendCategoryVideoBannerWithUid:[YTHsharedManger startManger].Uid vtid:_type_id withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
[self SpreadRequest];
|
[self getHomeType];
|
if (isSuccessful) {
|
NSDictionary *dic = (NSDictionary *)result;
|
if (!_dataAdverti) {
|
_dataAdverti = [[NSMutableArray alloc] initWithCapacity:0];
|
}
|
_dataAdverti = [[dic objectForKey:@"Data"] objectForKey:@"data"];
|
|
//存储获取到的数据
|
// NSData *data = [NSKeyedArchiver archivedDataWithRootObject:_dataAdverti];
|
// [data writeToFile:ADVERTISEFILE atomically:YES];
|
// [_recommentCollectionView reloadData];
|
NSLog(@"<------- %@ --------->",_dataAdverti);
|
//结束刷新
|
UICollectionView *collectview = self.collectArray[maintypeNumber];
|
[self.dataDic setValue:_dataAdverti forKey:@"ad"];
|
[self.allDataSourece removeObjectAtIndex:maintypeNumber];
|
[self.allDataSourece insertObject:self.dataDic atIndex:maintypeNumber];
|
[collectview.mj_header endRefreshing];
|
[self addSliderView];
|
}else{
|
//提示网络不稳定
|
UICollectionView *collectview = self.collectArray[maintypeNumber];
|
[collectview.mj_header endRefreshing];
|
// [self addSliderView];
|
|
}
|
}];
|
}
|
|
|
}
|
|
/**
|
* 小广告推广视图
|
*/
|
- (void)SpreadRequest{
|
|
if (!_adView) {
|
_adView = [[WeiKouAdView alloc]initWithFrame:CGRectMake(0.0, 0.0, KScreenW, KScreenW/6) withBlock:^(NSString *text) {
|
// [_recommentCollectionView reloadData];
|
// UICollectionView *collectView = [self viewWithTag:collectTag +maintypeNumber];
|
UICollectionView *collectview = self.collectArray[maintypeNumber];
|
// [collectview reloadData];
|
// [self collectLoadNewData];
|
|
}];
|
}
|
}
|
|
/**
|
* 获取推荐分类
|
*/
|
- (void)getHomeType{
|
NSLog(@"%@",_type_id);
|
UIViewController *viewcontroller = [self topViewController];
|
if ([_type_id integerValue] == 309 || [_type_id integerValue] == 310) {
|
[[YTHNetInterface startInterface] getHomeTypeWithUid:[YTHsharedManger startManger].Uid vtid:_type_id withSystem:@"1" DataKey:@"" PageSize:1 Page:1 withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
|
if (isSuccessful) {
|
NSDictionary *dic = (NSDictionary *)result;
|
if (!_dataHomeType) {
|
_dataHomeType = [[NSMutableArray alloc] initWithCapacity:0];
|
}
|
NSMutableArray *arr = [[dic objectForKey:@"Data"] objectForKey:@"data"];
|
|
_dataHomeType=arr;
|
[self.dataDic setValue:arr forKey:@"shopping"];
|
[self.allDataSourece removeObjectAtIndex:maintypeNumber];
|
[self.allDataSourece insertObject:self.dataDic atIndex:maintypeNumber];
|
//跟新视图数据
|
// [_recommentCollectionView reloadData];
|
// UICollectionView *collectview = [self viewWithTag:collectTag + maintypeNumber];
|
UICollectionView *collectview = self.collectArray[maintypeNumber];
|
|
[collectview.mj_header endRefreshing];
|
// [collectview reloadData];
|
// [self collectLoadNewData];
|
|
[self loadStarsData];
|
// NSData *data = [NSKeyedArchiver archivedDataWithRootObject:_dataHomeType];
|
// [data writeToFile:HOMETYPEFILE atomically:YES];
|
NSLog(@"<-。。。。%@、、、、、->",_dataHomeType);
|
NSLog(@"%ld",(unsigned long)_dataHomeType.count);
|
//请求明星分类,为什么要放在这里?因为明星分类是放在最后的,你必须知道推荐分类的个数,才好确定明星分类的个数
|
//结束刷新
|
collectview.mj_footer.hidden = NO;
|
|
|
//获取广点通原生广告数据
|
[self loadAd];
|
|
}else{
|
//提示网络不稳定
|
//UICollectionView *collectview = [self viewWithTag:collectTag + maintypeNumber];
|
UICollectionView *collectview = self.collectArray[maintypeNumber];
|
|
[collectview.mj_header endRefreshing];
|
if ([error compare:@"似乎已断开与互联网的连接。"] == 0) {
|
collectview.mj_footer.hidden = YES;
|
[viewcontroller autoDisappearAlertTime:1 msg:@"网络不可用,请检查网络"];
|
}else{
|
collectview.mj_footer.hidden = NO;
|
|
}
|
}
|
}];
|
}else{
|
// getRecommendCategoryVideoList
|
|
[[YTHNetInterface startInterface] getRecommendCategoryVideoListWithUid:[YTHsharedManger startManger].Uid withVideoType:_type_id withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
NSDictionary *dic = (NSDictionary *)result;
|
if (!_dataHomeType) {
|
_dataHomeType = [[NSMutableArray alloc] initWithCapacity:0];
|
}
|
NSMutableArray *arr = [[dic objectForKey:@"Data"] objectForKey:@"data"];
|
_dataHomeType=arr;
|
[self.dataDic setValue:arr forKey:@"shopping"];
|
[self.allDataSourece removeObjectAtIndex:maintypeNumber];
|
[self.allDataSourece insertObject:self.dataDic atIndex:maintypeNumber];
|
//跟新视图数据
|
UICollectionView *collectview = self.collectArray[maintypeNumber];
|
// [self collectLoadNewData];
|
|
// [collectview reloadData];
|
|
// NSData *data = [NSKeyedArchiver archivedDataWithRootObject:_dataHomeType];
|
// [data writeToFile:HOMETYPEFILE atomically:YES];
|
NSLog(@"<-。。。。%@、、、、、->",_dataHomeType);
|
//请求明星分类,为什么要放在这里?因为明星分类是放在最后的,你必须知道推荐分类的个数,才好确定明星分类的个数
|
[self loadStarsData];
|
//结束刷新
|
collectview.mj_footer.hidden = NO;
|
|
[collectview.mj_header endRefreshing];
|
//获取广点通原生广告数据
|
[self loadAd];
|
|
}else{
|
//提示网络不稳定
|
// UICollectionView *collectview = [self viewWithTag:collectTag + maintypeNumber];
|
UICollectionView *collectview = self.collectArray[maintypeNumber];
|
// [collectview reloadData];
|
[collectview.mj_header endRefreshing];
|
if ([error compare:@"似乎已断开与互联网的连接。"] == 0) {
|
collectview.mj_footer.hidden = YES;
|
[viewcontroller autoDisappearAlertTime:1 msg:@"网络不可用,请检查网络"];
|
}else{
|
collectview.mj_footer.hidden = NO;
|
}
|
}
|
}];
|
}
|
}
|
- (UIViewController *)_topViewController:(UIViewController *)vc {
|
if ([vc isKindOfClass:[UINavigationController class]]) {
|
return [self _topViewController:[(UINavigationController *)vc topViewController]];
|
} else if ([vc isKindOfClass:[UITabBarController class]]) {
|
return [self _topViewController:[(UITabBarController *)vc selectedViewController]];
|
} else {
|
return vc;
|
}
|
return nil;
|
}
|
- (UIViewController *)topViewController {
|
|
UIViewController *resultVC;
|
resultVC = [self _topViewController:[[UIApplication sharedApplication].keyWindow rootViewController]];
|
while (resultVC.presentedViewController) {
|
resultVC = [self _topViewController:resultVC.presentedViewController];
|
}
|
return resultVC;
|
}
|
|
/**
|
* 定制轮播图
|
*/
|
-(void)addSliderView{
|
if (_addrssForshuffling) {
|
_addrssForshuffling=nil;
|
}
|
_addrssForshuffling = [[NSMutableArray alloc] initWithCapacity:0];
|
_TitleForshuffling=[[NSMutableArray alloc] initWithCapacity:0];
|
//判断
|
NSLog(@"%@",_dataAdverti);
|
NSLog(@"%ld",(unsigned long)_dataAdverti.count);
|
_dataAdverti = self.allDataSourece[maintypeNumber][@"ad"];
|
if ([_type_id integerValue] == 309 || [_type_id integerValue] == 310) {
|
for (int i = 0; i<_dataAdverti.count; i++) {
|
NSLog(@"%@",[_dataAdverti objectAtIndex:i]);
|
[_addrssForshuffling addObject:[[_dataAdverti objectAtIndex:i] objectForKey:@"Picture"]];
|
// [_TitleForshuffling addObject:[[[_dataAdverti objectAtIndex:i] objectForKey:@"Video"] objectForKey:@"Name"]];
|
}
|
}else{
|
for (int i = 0; i<_dataAdverti.count; i++) {
|
NSLog(@"%@",[_dataAdverti objectAtIndex:i]);
|
[_addrssForshuffling addObject:[[_dataAdverti objectAtIndex:i] objectForKey:@"Picture"]];
|
// [_TitleForshuffling addObject:[[[_dataAdverti objectAtIndex:i] objectForKey:@"VideoType"] objectForKey:@"Name"]];
|
}
|
}
|
for (NSInteger index = 0; index < _TitleForshuffling.count; index ++) {
|
NSLog(@"、、、、、%@、、、、、",_TitleForshuffling[index]);
|
}
|
if ([_type_id integerValue] == 310) {
|
_cycleScrollView = [[BSKImagesPageView alloc]initWithFrame:CGRectMake(0, 0,KScreenW, KScreenH / 3.12) imageNames:_addrssForshuffling];
|
}else{
|
_cycleScrollView = [[BSKImagesPageView alloc]initWithFrame:CGRectMake(0, 0,KScreenW, KScreenW*7/16) imageNames:_addrssForshuffling];
|
}
|
_cycleScrollView.timerTimeInterval = 2;
|
_cycleScrollView.delegate = self;
|
// 375 * 667
|
// 320 * 364
|
// 568 / 182
|
}
|
|
/**
|
请求明星数据
|
*/
|
-(void)loadStarsData{
|
// getHotStarMainList
|
[[YTHNetInterface startInterface] getHotStarMainList:[YTHsharedManger startManger].Uid WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if(isSuccessful){
|
NSDictionary *dic = (NSDictionary *)result;
|
if(!_dataStar){
|
_dataStar=[NSMutableArray arrayWithCapacity:0];
|
}
|
_dataStar= [[dic objectForKey:@"Data"] objectForKey:@"data"];
|
|
//刷新视图
|
// UICollectionView *collectview = [self viewWithTag:collectTag + maintypeNumber];
|
UICollectionView *collectview = self.collectArray[maintypeNumber];
|
[self collectLoadNewData];
|
|
// [collectview reloadData];
|
//存储获取到的数据
|
// NSData *data = [NSKeyedArchiver archivedDataWithRootObject:_dataStar];
|
// [data writeToFile:DISCOVERSTAR atomically:YES];
|
}else{
|
NSLog(@"%@",error);
|
// UICollectionView *collectview = [self viewWithTag:collectTag + maintypeNumber];
|
// UICollectionView *collectview = self.collectArray[maintypeNumber];
|
[self collectLoadNewData];
|
|
// [collectview reloadData];
|
}
|
}];
|
|
}
|
|
/**
|
* 点击分类中的更多
|
*/
|
-(void)GetMoreInformationAboutClassification:(UIButton *)sender{
|
//查看更多明星合集
|
if((sender.tag-500)==[_dataHomeType count]+1){
|
StarsController* star = [StarsController new];
|
[[self viewController].navigationController pushViewController:star animated:YES];
|
return;
|
}
|
//其他分类
|
NSString *s = [[_dataHomeType[sender.tag-501] objectForKey:@"Params"] stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@\"",@"\\"] withString:@"\""];
|
NSDictionary *Params = [self dictionaryWithJsonString:s];
|
//因为福利社的样式是与其他分类的更多信息不一样,所以,必须要做一个判断
|
|
if ([[Params objectForKey:@"Name"] rangeOfString:@"福利"].location !=NSNotFound) {
|
//首先,你需要判断ShowAd是否为空
|
NSUserDefaults *uid = [NSUserDefaults standardUserDefaults];
|
if([uid objectForKey:@"ShowAd"]==nil){
|
[uid setValue:@"1" forKey:@"ShowAd"];
|
}
|
if ([[uid objectForKey:@"ShowAd"] intValue]==1) {
|
//提示用户去给好评
|
LXAlertView *alert=[[LXAlertView alloc] initWithTitle:@"titleImage2" message:@"赏个好评,解锁更多福利\n~ (^_^)∠※" cancelBtnTitle:@"改天" otherBtnTitle:@"好的" clickIndexBlock:^(NSInteger clickIndex) {
|
if(clickIndex==0){//不去评价
|
|
}else if(clickIndex==1){//去评价
|
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/bu-wan-ying-shi-da-quan-bao/id1135798414?mt=8"]];
|
[uid setValue:@"0" forKey:@"ShowAd"];
|
}
|
}];
|
alert.animationStyle=LXASAnimationTopShake;
|
[alert showLXAlertView];
|
}else{
|
FuLiSheViewController *FLSVC=[[FuLiSheViewController alloc] init];
|
FLSVC.Id=[Params objectForKey:@"Id"];
|
FLSVC.titles=[Params objectForKey:@"Name"];
|
[[self viewController].navigationController pushViewController:FLSVC animated:YES];
|
}
|
}else{
|
SubregionDetailViewController *subregionVC=[[SubregionDetailViewController alloc] init];
|
subregionVC.Id=[Params objectForKey:@"Id"];
|
subregionVC.titles=[Params objectForKey:@"Name"];
|
[[self viewController].navigationController pushViewController:subregionVC animated:YES];
|
}
|
}
|
|
/**
|
* 加载广点通原生广告
|
*/
|
-(void)loadAd{
|
|
self.nativeExpressAd = [self loadAdWithId:GDTYSADkey2 adSize:CGSizeMake((KScreenW-30)/2, (KScreenW-30)*10/32+55)];
|
self.secNativeExpressAd = [self loadAdWithId:GDTYSADkey8 adSize:CGSizeMake(KScreenW, (KScreenW-20)/16*9 + 10)];
|
self.thiNativeExpressAd = [self loadAdWithId:GDTYSADkey9 adSize:CGSizeMake(KScreenW, (KScreenW-20)/16*9 + 10)];
|
self.clSecNativeExpressAd = [self loadAdWithId:GDTYSADkey10 adSize:CGSizeMake((KScreenW-30)/2, (KScreenW-30)*10/32+55)];
|
self.clThiNativeExpressAd = [self loadAdWithId:GDTYSADkey11 adSize:CGSizeMake(KScreenW, (KScreenW-20)/16*9 + 10)];
|
}
|
- (GDTNativeExpressAd *)loadAdWithId:(NSString *)placementId adSize:(CGSize)adSize{
|
GDTNativeExpressAd * expressAd = [[GDTNativeExpressAd alloc] initWithPlacementId:placementId adSize:adSize];
|
expressAd.delegate = self;
|
// 配置视频播放属性
|
expressAd.videoAutoPlayOnWWAN = YES;
|
expressAd.videoMuted = NO;
|
[expressAd loadAd:1];
|
return expressAd;
|
}
|
|
//在主线程刷新collectview,非主线程不能刷新
|
- (void)collectLoadNewData{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
[UIView setAnimationsEnabled:NO];
|
[CATransaction setDisableActions:YES];
|
UICollectionView *collectview = self.collectArray[maintypeNumber];
|
[collectview reloadData];
|
collectview.scrollEnabled = YES;
|
[CATransaction commit];
|
[UIView setAnimationsEnabled:YES];
|
|
});
|
}
|
#pragma mark 把json格式的字符串转换为字典格式
|
- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
|
if (jsonString == nil) {
|
return nil;
|
}
|
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
|
NSError *err;
|
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
|
options:NSJSONReadingMutableContainers
|
error:&err];
|
if(err) {
|
NSLog(@"json解析失败:%@",err);
|
return nil;
|
}
|
return dic;
|
}
|
/**
|
* 返回当前视图的控制器
|
*/
|
- (UIViewController *)viewController {
|
for (UIView* next = [self superview]; next; next = next.superview) {
|
UIResponder *nextResponder = [next nextResponder];
|
if ([nextResponder isKindOfClass:[UIViewController class]]) {
|
return (UIViewController *)nextResponder;
|
}
|
}
|
return nil;
|
}
|
|
/**************(以下)协议区******************/
|
#pragma mark -UICollection----ViewDataSource
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
NSArray * dataHomeType = self.allDataSourece[maintypeNumber][@"shopping"];
|
|
if (section==0) {
|
return 0;
|
}else
|
if ([_type_id integerValue] == 309 || [_type_id integerValue] == 310) {
|
if (dataHomeType.count!=0) {
|
NSArray *arr=[dataHomeType[section-1] objectForKey:@"HomeVideoList"];
|
NSLog(@"%@",dataHomeType);
|
return arr.count;
|
}else {
|
return 0;
|
}
|
}else{
|
if (dataHomeType.count!=0) {
|
return dataHomeType.count;
|
}else{
|
return 0;
|
|
}
|
}
|
}
|
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
|
if (self.allDataSourece.count == 0) {
|
return 0;
|
}
|
NSArray * dataHomeType = self.allDataSourece[maintypeNumber][@"shopping"];
|
if ([_type_id integerValue] == 309 || [_type_id integerValue] == 310) {
|
return dataHomeType.count+1;
|
}else{
|
return 2;
|
}
|
}
|
|
/*
|
* collectview加载数据 *
|
*/
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
_dataHomeType = self.allDataSourece[maintypeNumber][@"shopping"];
|
if ([_type_id integerValue] == 309 || [_type_id integerValue] == 310) {
|
if (indexPath.section!=_dataHomeType.count+1) {
|
if (indexPath.section >=- _dataHomeType.count) {
|
return nil;
|
}
|
if (indexPath.row == 0 && indexPath.section == 1) {
|
|
AdCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"AdCollectionViewCell" forIndexPath:indexPath];
|
GDTNativeExpressAdView *adView ;
|
if ([_type_id integerValue] == 309) {
|
adView = (GDTNativeExpressAdView *)self.expressAdViews[0];
|
}else{
|
adView = (GDTNativeExpressAdView *)self.clSecExpressAdViews[0];
|
}
|
adView.frame = cell.bounds;
|
[cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
|
[cell.contentView addSubview: adView];
|
|
//添加阴影
|
cell.layer.masksToBounds = NO;
|
cell.layer.contentsScale = [UIScreen mainScreen].scale;
|
cell.layer.shadowOpacity = 0.7f;
|
cell.layer.shadowRadius = 1.0f;
|
cell.layer.shadowOffset = CGSizeMake(0,2);
|
cell.layer.shadowPath = [UIBezierPath bezierPathWithRect:cell.bounds].CGPath;
|
cell.layer.shadowColor = kGlobalLightGreyColor_223.CGColor;
|
//设置缓存
|
cell.layer.shouldRasterize = YES;
|
//设置抗锯齿边缘
|
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
|
return cell;
|
}
|
|
recommentCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"recommentCollectionViewCell" forIndexPath:indexPath];
|
//设置cell的背景色(白色)
|
cell.backgroundColor=[UIColor whiteColor];
|
|
|
//在这里对cell进行设置
|
if (_dataHomeType.count < indexPath.section) {
|
return cell;
|
}
|
|
NSArray *HomeVideoList=[_dataHomeType[indexPath.section-1] objectForKey:@"HomeVideoList"];
|
if (indexPath.row >= HomeVideoList.count) {
|
return cell;
|
}
|
|
NSDictionary *VideoInformation=HomeVideoList[indexPath.row];
|
NSString *picStr=[VideoInformation objectForKey:@"Picture"];
|
NSDictionary *VideoDic=[VideoInformation objectForKey:@"Video"];
|
//设置图片
|
cell.recommentImageView.contentMode=UIViewContentModeScaleAspectFill;
|
if (picStr.length>1) {
|
// NSString *path = [[NSBundle mainBundle] pathForResource:picStr ofType:@"gif"];
|
// NSData *data = [NSData dataWithContentsOfFile:path];
|
// UIImage *image = [UIImage sd_animatedGIFWithData:data];
|
// cell.recommentImageView.image = image;
|
// [cell.recommentImageView sd_setImageWithURL:[NSURL URLWithString:picStr]];
|
[cell.recommentImageView setYthImageWithURL:picStr placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
|
}else{
|
picStr=[VideoDic objectForKey:@"Picture"];
|
[cell.recommentImageView setYthImageWithURL:picStr placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
|
}
|
//设置短评(如果有Tag就设置Tag,没有Tag就设置Score)
|
NSString *TagStr1=[VideoInformation objectForKey:@"Tag"];
|
NSString *TagStr2=[VideoDic objectForKey:@"Tag"];
|
NSString *Score=[VideoDic objectForKey:@"Score"];
|
cell.recommentReplyLabel.hidden = NO;
|
if(TagStr1.length>1){
|
cell.recommentReplyLabel.text=TagStr1;
|
}else if(TagStr2.length>1){
|
cell.recommentReplyLabel.text=TagStr2;
|
}else if([Score intValue]>0){
|
cell.recommentReplyLabel.hidden = YES;
|
|
cell.recommentReplyLabel.text=[NSString stringWithFormat:@"评分:%@",Score];
|
}else{
|
cell.recommentReplyLabel.text=[NSString stringWithFormat:@"评分:无"];
|
cell.recommentReplyLabel.hidden = YES;
|
|
}
|
cell.recommentReplyLabel.backgroundColor=[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.7];
|
//标题
|
cell.recommentTitleLabel.text=[NSString stringWithFormat:@"%@",[VideoDic objectForKey:@"Name"]];
|
//观看数量
|
cell.recommentrecommentVV.textColor=kGlobalLightGreyColor_210;
|
NSString *recommentStr;
|
if([VideoDic objectForKey:@"WatchCount"]==nil||[[VideoDic objectForKey:@"WatchCount"] isEqualToString:@"(null)"]){
|
recommentStr=[NSString stringWithFormat:@"0"];
|
}else if ([[VideoDic objectForKey:@"WatchCount"] intValue]<10000) {
|
recommentStr=[VideoDic objectForKey:@"WatchCount"];
|
}else{
|
recommentStr=[NSString stringWithFormat:@"%0.1f万",[[VideoDic objectForKey:@"WatchCount"] floatValue]/10000.0];
|
}
|
cell.recommentrecommentVV.text=recommentStr;
|
//评论数量CommentCount
|
cell.recommentCommentNub.textColor=kGlobalLightGreyColor_210;
|
NSString *commentCountStr;
|
if ([VideoDic objectForKey:@"CommentCount"]==nil) {
|
commentCountStr=[NSString stringWithFormat:@"0"];
|
}else if ([[VideoDic objectForKey:@"CommentCount"] intValue]<10000) {
|
commentCountStr=[VideoDic objectForKey:@"CommentCount"];
|
}else{
|
commentCountStr=[NSString stringWithFormat:@"%0.1f万",[[VideoDic objectForKey:@"CommentCount"] floatValue]/10000.0];
|
}
|
cell.recommentCommentNub.text=[NSString stringWithFormat:@"%@",commentCountStr];
|
cell.recommentCommentNub.hidden = YES;
|
cell.pinglunPic.hidden = YES;
|
//添加阴影
|
cell.layer.masksToBounds = NO;
|
cell.layer.contentsScale = [UIScreen mainScreen].scale;
|
cell.layer.shadowOpacity = 0.7f;
|
cell.layer.shadowRadius = 1.0f;
|
cell.layer.shadowOffset = CGSizeMake(0,2);
|
cell.layer.shadowPath = [UIBezierPath bezierPathWithRect:cell.bounds].CGPath;
|
cell.layer.shadowColor = kGlobalLightGreyColor_223.CGColor;
|
//设置缓存
|
cell.layer.shouldRasterize = YES;
|
//设置抗锯齿边缘
|
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
|
|
return cell;
|
}
|
else{
|
StartCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"StartCollectionViewCell" forIndexPath:indexPath];
|
// [cell.image setYthImageWithURL:[_dataStar[indexPath.row] objectForKey:@"Portrait"] placeholderImage:[UIImage imageNamed:@"关注默认头像"]];
|
// [cell.name setText:[_dataStar[indexPath.row] objectForKey:@"Name"]];
|
return cell;
|
}
|
}else{
|
if (indexPath.row < _dataHomeType.count) {
|
if (indexPath.row == 0 && indexPath.section == 1) {
|
AdCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"AdCollectionViewCell" forIndexPath:indexPath];
|
|
GDTNativeExpressAdView *adView = (GDTNativeExpressAdView *)self.clSecExpressAdViews[0];
|
adView.frame = cell.bounds;
|
[cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
|
[cell.contentView addSubview: adView];
|
//添加阴影
|
cell.layer.masksToBounds = NO;
|
cell.layer.contentsScale = [UIScreen mainScreen].scale;
|
cell.layer.shadowOpacity = 0.7f;
|
cell.layer.shadowRadius = 1.0f;
|
cell.layer.shadowOffset = CGSizeMake(0,2);
|
cell.layer.shadowPath = [UIBezierPath bezierPathWithRect:cell.bounds].CGPath;
|
cell.layer.shadowColor = kGlobalLightGreyColor_223.CGColor;
|
//设置缓存
|
cell.layer.shouldRasterize = YES;
|
//设置抗锯齿边缘
|
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
|
return cell;
|
}
|
|
recommentCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"recommentCollectionViewCell" forIndexPath:indexPath];
|
// if (indexPath.row > _dataHomeType.count) {
|
// return cell;
|
// }f
|
|
//设置cell的背景色(白色)
|
cell.backgroundColor=[UIColor whiteColor];
|
|
//在这里对cell进行设置
|
// NSArray *HomeVideoList=_dataHomeType[indexPath.row];
|
|
NSDictionary *VideoInformation=_dataHomeType[indexPath.row];
|
NSString *picStr=[VideoInformation objectForKey:@"Picture"];
|
NSDictionary *VideoDic=VideoInformation;
|
//设置图片
|
cell.recommentImageView.contentMode=UIViewContentModeScaleAspectFill;
|
if (picStr.length>1) {
|
[cell.recommentImageView setYthImageWithURL:picStr placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
|
}else{
|
picStr=[VideoDic objectForKey:@"Picture"];
|
[cell.recommentImageView setYthImageWithURL:picStr placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
|
}
|
//设置短评(如果有Tag就设置Tag,没有Tag就设置Score)
|
NSString *TagStr1=[VideoInformation objectForKey:@"Tag"];
|
NSString *TagStr2=[VideoDic objectForKey:@"Tag"];
|
NSString *Score=[VideoDic objectForKey:@"Score"];
|
NSLog(@"%@ -- %@ -- %@",TagStr1,TagStr2,Score);
|
NSLog(@"----%@ ---- %@ ----",VideoDic,_dataHomeType[indexPath.row]);
|
if ([TagStr1 isEqual:[NSNull null]])
|
{
|
TagStr1 = @"";
|
}
|
if ([TagStr2 isEqual:[NSNull null]])
|
{
|
TagStr2 = @"";
|
}
|
if ([Score isEqual:[NSNull null]])
|
{
|
Score = @"";
|
}
|
if(TagStr1.length>1){
|
cell.recommentReplyLabel.text=TagStr1;
|
}else if(TagStr2.length>1){
|
cell.recommentReplyLabel.text=TagStr2;
|
}else if([Score intValue]>0){
|
cell.recommentReplyLabel.text=[NSString stringWithFormat:@"评分:%@",Score];
|
cell.recommentReplyLabel.hidden = NO;
|
}else{
|
//cell.recommentReplyLabel.text=[NSString stringWithFormat:@"评分:无"];
|
cell.recommentReplyLabel.hidden = YES;
|
}
|
cell.recommentReplyLabel.backgroundColor=[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.7];
|
//标题
|
cell.recommentTitleLabel.text=[NSString stringWithFormat:@"%@",[VideoInformation objectForKey:@"Name"]];
|
//观看数量
|
cell.recommentrecommentVV.textColor=kGlobalLightGreyColor_210;
|
NSString *recommentStr;
|
if([VideoDic objectForKey:@"WatchCount"]==nil||[[VideoDic objectForKey:@"WatchCount"] isEqualToString:@"(null)"]){
|
recommentStr=[NSString stringWithFormat:@"0"];
|
}else if ([[VideoDic objectForKey:@"WatchCount"] intValue]<10000) {
|
recommentStr=[VideoDic objectForKey:@"WatchCount"];
|
}else{
|
recommentStr=[NSString stringWithFormat:@"%0.1f万",[[VideoDic objectForKey:@"WatchCount"] floatValue]/10000.0];
|
}
|
cell.recommentrecommentVV.text=recommentStr;
|
//评论数量CommentCount
|
cell.recommentCommentNub.textColor=kGlobalLightGreyColor_210;
|
NSString *commentCountStr;
|
if ([VideoDic objectForKey:@"CommentCount"]==nil) {
|
commentCountStr=[NSString stringWithFormat:@"0"];
|
}else if ([[VideoDic objectForKey:@"CommentCount"] intValue]<10000) {
|
commentCountStr=[VideoDic objectForKey:@"CommentCount"];
|
}else{
|
commentCountStr=[NSString stringWithFormat:@"%0.1f万",[[VideoDic objectForKey:@"CommentCount"] floatValue]/10000.0];
|
}
|
cell.recommentCommentNub.text=[NSString stringWithFormat:@"%@",commentCountStr];
|
cell.recommentCommentNub.hidden = YES;
|
cell.pinglunPic.hidden = YES;
|
//添加阴影
|
cell.layer.masksToBounds = NO;
|
cell.layer.contentsScale = [UIScreen mainScreen].scale;
|
cell.layer.shadowOpacity = 0.7f;
|
cell.layer.shadowRadius = 1.0f;
|
cell.layer.shadowOffset = CGSizeMake(0,2);
|
cell.layer.shadowPath = [UIBezierPath bezierPathWithRect:cell.bounds].CGPath;
|
cell.layer.shadowColor = kGlobalLightGreyColor_223.CGColor;
|
//设置缓存
|
cell.layer.shouldRasterize = YES;
|
//设置抗锯齿边缘
|
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
|
return cell;
|
}else{
|
// StartCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"StartCollectionViewCell" forIndexPath:indexPath];
|
// [cell.image setYthImageWithURL:[_dataStar[indexPath.row] objectForKey:@"Portrait"] placeholderImage:[UIImage imageNamed:@"关注默认头像"]];
|
// [cell.name setText:[_dataStar[indexPath.row] objectForKey:@"Name"]];
|
// return cell;
|
recommentCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"recommentCollectionViewCell" forIndexPath:indexPath];
|
|
return cell;
|
}
|
|
}
|
|
}
|
|
//定制collectionView的head和foot
|
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
|
if (kind == UICollectionElementKindSectionHeader){
|
if(indexPath.section==0){
|
//如果是轮播图
|
shufflingCollectionReusableView *shuffling=[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"shufflingCollectionReusableView" forIndexPath:indexPath];
|
//如果之前已经加载了轮播图,就不能再添加轮播图了,所以需要遍历子视图,并移除
|
for(UIView *view in [shuffling subviews]){
|
[view removeFromSuperview];
|
}
|
//定制轮播图
|
[shuffling addSubview:_cycleScrollView];
|
return shuffling;
|
}else if(indexPath.section==_dataHomeType.count+1){
|
HeaderCollectionReusableView *header=[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderCollectionReusableView" forIndexPath:indexPath];
|
[header.headerImage setImage:[UIImage imageNamed:@"明星合集"]];
|
header.HeaderTitle.text=@"明星合集";
|
header.headerMore.tag=500+indexPath.section;
|
[header.headerMore addTarget:self action:@selector(GetMoreInformationAboutClassification:) forControlEvents:UIControlEventTouchUpInside];
|
// [header.headerMore setHidden:NO];
|
return header;
|
}else {
|
//分类标头
|
HeaderCollectionReusableView *header=[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderCollectionReusableView" forIndexPath:indexPath];
|
|
if ([_type_id integerValue] == 309 ) {
|
[header.headerImage setYthImageWithURL:[_dataHomeType[indexPath.section-1] objectForKey:@"Icon"] placeholderImage:[UIImage imageNamed:@"今日热点"]];
|
header.HeaderTitle.text=[_dataHomeType[indexPath.section-1] objectForKey:@"Name"];
|
if([[_dataHomeType[indexPath.section-1] objectForKey:@"HasMore"] boolValue]){
|
header.headerMore.tag=500+indexPath.section;
|
[header.headerMore addTarget:self action:@selector(GetMoreInformationAboutClassification:) forControlEvents:UIControlEventTouchUpInside];
|
// [header.headerMore setHidden:NO];
|
}else{
|
// [header.headerMore setHidden:YES];
|
}
|
return header;
|
}else if([_type_id integerValue] == 310){
|
header.headerImage.image = [UIImage imageNamed:@"明星合辑"];
|
header.HeaderTitle.text=[_dataHomeType[indexPath.section-1] objectForKey:@"Name"];
|
if([[_dataHomeType[indexPath.section-1] objectForKey:@"HasMore"] boolValue]){
|
header.headerMore.tag=500+indexPath.section;
|
[header.headerMore addTarget:self action:@selector(GetMoreInformationAboutClassification:) forControlEvents:UIControlEventTouchUpInside];
|
}
|
return header;
|
}else{
|
// [header.headerMore setHidden:YES];
|
header.headerImage.image = [UIImage imageNamed:@"今日热点"];
|
header.HeaderTitle.text = @"热播推荐";
|
return header;
|
}
|
|
}
|
}
|
if (kind == UICollectionElementKindSectionFooter) {
|
if (indexPath.section == 0) {
|
//放置小广告
|
FooterCollectionReusableView *footer=[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterCollectionReusableView" forIndexPath:indexPath];
|
//添加小广告视图
|
[footer setBackgroundColor:kGlobalBackgroundColor];
|
//这种情况是排除banner广告未加载出来的情况
|
if(_adView!=nil){
|
[footer addSubview:_adView];
|
footer.hidden = YES;
|
return footer;
|
}else{
|
return nil;
|
}
|
return footer;
|
|
} else {
|
if (indexPath.section==1) {
|
//返回广告视图
|
ADCollectionReusableView *groupfootSection = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"ADCollectionReusableView" forIndexPath:indexPath];
|
|
GDTNativeExpressAdView *adView;
|
if ([_type_id integerValue] == 309) {
|
adView = (GDTNativeExpressAdView *)self.secExpressAdViews[0];
|
}else{
|
adView = (GDTNativeExpressAdView *)self.clThiExpressAdViews[0];
|
}
|
[groupfootSection addSubview:adView];
|
return groupfootSection;
|
}
|
// else if (indexPath.section==_dataHomeType.count){
|
//
|
//
|
// UICollectionReusableView *reusableFootView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"UICollectionReusableView" forIndexPath:indexPath];
|
//
|
// if(googleNoAdToShow){//加载芒果广告
|
//
|
// return reusableFootView;
|
// } else {
|
// if (self.nativeAdView!=nil) {
|
//
|
// return reusableFootView;
|
// }
|
// }
|
// }
|
}
|
}
|
UICollectionReusableView *reusableFootView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"UICollectionReusableView" forIndexPath:indexPath];
|
return reusableFootView;
|
}
|
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
|
//宽度随便定,系统会自动取collectionView的宽度
|
//高度为分组头的高度
|
if(section==0){
|
//设置轮播图的高度
|
if ([_type_id integerValue] == 310) {
|
return CGSizeMake(0, KScreenH / 3.12);
|
}else{
|
return CGSizeMake(0, KScreenW*7/16);
|
}
|
}else{
|
return CGSizeMake(0, 50);
|
}
|
}
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
|
|
if (section==0) {
|
// if(_adView!=nil){
|
// if(_adView.dataArray.count>0){
|
// return CGSizeMake(0, 50);
|
// }else{
|
// return CGSizeMake(0, 0);
|
// }
|
// }else{
|
return CGSizeMake(0, 0);
|
// }
|
}else if(section==1){
|
if (self.expressAdViews==nil) {
|
return CGSizeMake(0, 0);
|
|
} else {
|
GDTNativeExpressAdView *adView = (GDTNativeExpressAdView *)self.secExpressAdViews[0];
|
return CGSizeMake(0, adView.bounds.size.height);
|
}
|
|
} else if (section == _dataHomeType.count) {
|
if(googleNoAdToShow){
|
if (self.expressAdViews==nil) {
|
return CGSizeMake(0, 0);
|
|
} else {
|
return CGSizeMake(0, 0);
|
}
|
|
}else{
|
if (self.nativeAdView==nil) {
|
return CGSizeMake(0, 0);
|
}else{
|
return CGSizeMake(0, 0);
|
}
|
}
|
}else{
|
return CGSizeMake(0, 0);
|
}
|
}
|
#pragma mark -UICollectionViewDelegate
|
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
|
return YES;
|
}
|
|
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
return YES;
|
}
|
|
//cell被点击的处理方法
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
if (self.dataAdverti == nil || self.dataAdverti.count<1) {
|
return;
|
}
|
if (indexPath.section==_dataHomeType.count+1) {
|
IndividualStarController * IndividualStarVC = [IndividualStarController new];
|
IndividualStarVC.data = _dataStar[indexPath.row];
|
[[self viewController].navigationController pushViewController:IndividualStarVC animated:YES];
|
}else{
|
|
NSString *s = [[_dataHomeType[indexPath.section-1] objectForKey:@"Params"] stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@\"",@"\\"] withString:@"\""];
|
NSDictionary *Params = [self dictionaryWithJsonString:s];
|
|
//因为福利社的样式是与其他分类的更多信息不一样,所以,必须要做一个判断
|
NSLog( @"%@",Params);
|
NSLog(@"%@",[Params objectForKey:@"Name"]);
|
if ([[Params objectForKey:@"Name"] rangeOfString:@"福利"].location !=NSNotFound && Params != nil) {
|
//首先,你需要判断ShowAd是否为空
|
NSUserDefaults *uid = [NSUserDefaults standardUserDefaults];
|
if([uid objectForKey:@"ShowAd"]==nil){
|
[uid setValue:@"1" forKey:@"ShowAd"];
|
}
|
if ([[uid objectForKey:@"ShowAd"] intValue]==1) {
|
//提示用户去给好评
|
LXAlertView *alert=[[LXAlertView alloc] initWithTitle:@"titleImage2" message:@"赏个好评,解锁更多福利\n~ (^_^)∠※" cancelBtnTitle:@"改天" otherBtnTitle:@"好的" clickIndexBlock:^(NSInteger clickIndex) {
|
if(clickIndex==0){//不去评价
|
|
}else if(clickIndex==1){//去评价
|
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/bu-wan-ying-shi-da-quan-bao/id1135798414?mt=8"]];
|
[uid setValue:@"0" forKey:@"ShowAd"];
|
}
|
}];
|
alert.animationStyle=LXASAnimationTopShake;
|
[alert showLXAlertView];
|
}else{
|
if (indexPath.section==_dataHomeType.count+1) {
|
IndividualStarController * IndividualStarVC = [IndividualStarController new];
|
IndividualStarVC.data = _dataStar[indexPath.row];
|
[[self viewController].navigationController pushViewController:IndividualStarVC animated:YES];
|
}else{
|
if ([_type_id integerValue] == 309 || [_type_id integerValue] == 310) {
|
NSArray *HomeVideoList=[self.dataHomeType[indexPath.section-1] objectForKey:@"HomeVideoList"];
|
XYRDetailViewController *play = [[XYRDetailViewController alloc]init];
|
[YTHsharedManger startManger].preController = [self viewController];
|
play.modalPresentationStyle = 0;
|
play.Model = [XYRVideoInfoModel yy_modelWithDictionary:[HomeVideoList[indexPath.row] objectForKey:@"Video"]];
|
[[self viewController] presentViewController:play animated:YES completion:^{
|
|
}];
|
|
} else {
|
NSDictionary *HomeVideoList=self.dataHomeType[indexPath.row];
|
XYRDetailViewController *play = [[XYRDetailViewController alloc]init];
|
[YTHsharedManger startManger].preController = [self viewController];
|
play.modalPresentationStyle = 0;
|
play.Model = [XYRVideoInfoModel yy_modelWithDictionary:HomeVideoList];
|
[[self viewController] presentViewController:play animated:YES completion:^{
|
|
}];
|
}
|
}
|
}
|
|
} else {
|
if ([_type_id integerValue] == 309 || [_type_id integerValue] == 310) {
|
NSArray *HomeVideoList=[self.dataHomeType[indexPath.section-1] objectForKey:@"HomeVideoList"];
|
XYRDetailViewController *play = [[XYRDetailViewController alloc]init];
|
[YTHsharedManger startManger].preController = [self viewController];
|
play.modalPresentationStyle = 0;
|
play.Model = [XYRVideoInfoModel yy_modelWithDictionary:[HomeVideoList[indexPath.row] objectForKey:@"Video"]];
|
[[self viewController] presentViewController:play animated:YES completion:^{
|
}];
|
|
} else {
|
NSDictionary *HomeVideoList=self.dataHomeType[indexPath.row] ;
|
XYRDetailViewController *play = [[XYRDetailViewController alloc]init];
|
[YTHsharedManger startManger].preController = [self viewController];
|
play.modalPresentationStyle = 0;
|
play.Model = [XYRVideoInfoModel yy_modelWithDictionary:HomeVideoList];
|
[[self viewController] presentViewController:play animated:YES completion:^{
|
}];
|
}
|
|
}
|
}
|
|
}
|
|
#pragma mark -UICollectionViewDelegateFlowLayout
|
//协议中的方法,用于返回单元格的大小
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
|
if(indexPath.section==_dataHomeType.count+1){
|
return CGSizeMake((KScreenW-100)/3, (KScreenW-100)/3+30);
|
}else{
|
return CGSizeMake((KScreenW-30)/2, (KScreenW-30)*10/32+55);
|
}
|
}
|
|
//协议中的方法,用于返回整个CollectionView上、左、下、右距四边的间距
|
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
|
//上、左、下、右的边距
|
if(section==_dataHomeType.count+1){
|
return UIEdgeInsetsMake(0, 25, 10, 25);
|
}else{
|
return UIEdgeInsetsMake(0, 10, 10, 10);
|
}
|
}
|
|
#pragma mark - BSKImagesPageViewViewDelegate
|
|
- (void)BSKImagesPageView:(BSKImagesPageView *)autoPlayScrollView onClickImageView:(UIImageView *)imageView atIndex:(NSInteger)index{
|
if (self.dataAdverti == nil || self.dataAdverti.count<1) {
|
return;
|
}
|
NSInteger LinkType = [[self.dataAdverti[index] objectForKey:@"LinkType"] integerValue];
|
if (LinkType == 1) {//普通视频跳转
|
XYRDetailViewController *play=[[XYRDetailViewController alloc]init];
|
[YTHsharedManger startManger].preController = [self viewController];
|
NSString *video = @"";
|
if ([_type_id integerValue] == 309 || [_type_id integerValue] == 310) {
|
video = @"Video";
|
}else{
|
video = @"VideoInfo";
|
}
|
NSLog(@"%@",self.dataAdverti[index]);
|
play.modalPresentationStyle = 0;
|
play.Model = [XYRVideoInfoModel yy_modelWithDictionary:[self.dataAdverti[index] objectForKey:video]];
|
[[self viewController] presentViewController:play animated:YES completion:^{
|
|
}];
|
}else if (LinkType == 2){//网页(网页)
|
//url
|
// NSString *s = [[self.dataAdverti[index] objectForKey:@"Params"] stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@\"",@"\\"] withString:@"\""];
|
NSString *s = [[self.dataAdverti[index] objectForKey:@"Params"] stringByReplacingOccurrencesOfString:@"\\"withString:@""];
|
|
NSDictionary *Params = [self dictionaryWithJsonString:s];
|
NSLog(@"%@",Params);
|
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[Params objectForKey:@"url"]]];
|
|
} else if (LinkType == 3){//专辑
|
OnlySpecialController *OnlySpecial =[OnlySpecialController new];
|
OnlySpecial.Id=[[self.dataAdverti[index] objectForKey:@"Id"] intValue];
|
[[self viewController].navigationController pushViewController:OnlySpecial animated:YES];
|
}
|
}
|
|
// Gets an image representing the number of stars. Returns nil if rating is less than 3.5 stars.
|
- (UIImage *)imageForStars:(NSDecimalNumber *)numberOfStars {
|
double starRating = [numberOfStars doubleValue];
|
if (starRating >= 5) {
|
return [UIImage imageNamed:@"stars_5"];
|
} else if (starRating >= 4.5) {
|
return [UIImage imageNamed:@"stars_4_5"];
|
} else if (starRating >= 4) {
|
return [UIImage imageNamed:@"stars_4"];
|
} else if (starRating >= 3.5) {
|
return [UIImage imageNamed:@"stars_3_5"];
|
} else {
|
return nil;
|
}
|
}
|
|
#pragma mark -GDTNativeAdDelegate
|
/**
|
* 原生广告加载广告数据成功回调,返回为GDTNativeAdData对象的数组
|
*/
|
//-(void)nativeAdSuccessToLoad:(NSArray *)nativeAdDataArray{
|
// if (!nativeArray) {
|
// nativeArray =[[NSMutableArray alloc]initWithArray:nativeAdDataArray];
|
// }else{
|
// nativeArray = nativeAdDataArray.mutableCopy;
|
// }
|
// nativeArray = nativeAdDataArray;
|
// [self collectLoadNewData];
|
|
// [collectview reloadData];
|
// [_recommentCollectionView reloadData];
|
//}
|
|
/**
|
* 原生广告加载广告数据失败回调
|
*/
|
-(void)nativeAdFailToLoad:(NSError *)error{
|
NSLog(@"XYR_%@",error);
|
}
|
- (void)nativeExpressAdSuccessToLoad:(GDTNativeExpressAd *)nativeExpressAd views:(NSArray<__kindof GDTNativeExpressAdView *> *)views
|
{
|
if (nativeExpressAd == self.nativeExpressAd) {
|
self.expressAdViews = [NSArray arrayWithArray:views];
|
if (self.expressAdViews.count) {
|
[self.expressAdViews enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
GDTNativeExpressAdView *expressView = (GDTNativeExpressAdView *)obj;
|
expressView.controller = [self XC_GetViewControllerWithView:self];
|
[expressView render];
|
}];
|
}
|
}
|
if (nativeExpressAd == self.secNativeExpressAd) {
|
self.secExpressAdViews = [NSArray arrayWithArray:views];
|
if (self.secExpressAdViews.count) {
|
[self.secExpressAdViews enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
GDTNativeExpressAdView *expressView = (GDTNativeExpressAdView *)obj;
|
expressView.controller = [self XC_GetViewControllerWithView:self];
|
[expressView render];
|
}];
|
}
|
}
|
if (nativeExpressAd == self.thiNativeExpressAd) {
|
self.thiExpressAdViews = [NSArray arrayWithArray:views];
|
if (self.thiExpressAdViews.count) {
|
[self.thiExpressAdViews enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
GDTNativeExpressAdView *expressView = (GDTNativeExpressAdView *)obj;
|
expressView.controller = [self XC_GetViewControllerWithView:self];
|
[expressView render];
|
}];
|
}
|
}
|
if (nativeExpressAd == self.clSecNativeExpressAd) {
|
self.clSecExpressAdViews = [NSArray arrayWithArray:views];
|
if (self.clSecExpressAdViews.count) {
|
[self.clSecExpressAdViews enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
GDTNativeExpressAdView *expressView = (GDTNativeExpressAdView *)obj;
|
expressView.controller = [self XC_GetViewControllerWithView:self];
|
[expressView render];
|
}];
|
}
|
}
|
if (nativeExpressAd == self.clThiNativeExpressAd) {
|
self.clThiExpressAdViews = [NSArray arrayWithArray:views];
|
if (self.clThiExpressAdViews.count) {
|
[self.clThiExpressAdViews enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
GDTNativeExpressAdView *expressView = (GDTNativeExpressAdView *)obj;
|
expressView.controller = [self XC_GetViewControllerWithView:self];
|
[expressView render];
|
}];
|
}
|
}
|
// 广告位 render 后刷新 tableView
|
[self collectLoadNewData];
|
}
|
- (UIViewController *)XC_GetViewControllerWithView:(UIView *)view
|
{
|
for (UIView* next = [view superview]; next; next = next.superview) {
|
UIResponder *nextResponder = [next nextResponder];
|
if ([nextResponder isKindOfClass:[UIViewController class]]) {
|
return (UIViewController *)nextResponder;
|
}
|
}
|
return nil;
|
|
}
|
- (void)nativeExpressAdFailToLoad:(GDTNativeExpressAd *)nativeExpressAd error:(NSError *)error{
|
NSLog(@"%@",error);
|
}
|
|
|
#pragma mark - UIScrollViewDelegate
|
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
|
CGFloat pageWidth =KScreenW;
|
NSInteger page = scrollView.contentOffset.x / pageWidth;
|
NSLog(@"%d",scrollView.mj_header.isRefreshing);
|
if([scrollView isKindOfClass:[UICollectionView class]]){
|
NSLog(@"");
|
}else{
|
if (scrollView.mj_header.isRefreshing) {
|
NSLog(@"%d",scrollView.mj_header.isRefreshing);
|
}else{
|
[self loadAd];
|
|
maintypeNumber = page;
|
_type_id = self.classArray[page][@"Id"];
|
// UICollectionView *collectview = self.collectArray[maintypeNumber];
|
// collectview.hidden = NO;
|
// [collectview scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0] atScrollPosition:UICollectionViewScrollPositionTop animated:NO];
|
|
[self.vidioGmentControl setSelectedSegmentIndex:page animated:YES];
|
// NSArray * dataHomeType = self.allDataSourece[maintypeNumber][@"shopping"];
|
//
|
// if (dataHomeType.count == 0) {
|
// collectview.scrollEnabled = NO;
|
[self loadNewData];
|
// }
|
|
}
|
}
|
|
}
|
//添加主UIScrollView
|
-(void)addScrollView {
|
|
if (KIsiPhoneX) {
|
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 40, KScreenW, self.frame.size.height-124)];
|
|
}else{
|
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 40, KScreenW, self.frame.size.height-104)];
|
|
}
|
_scrollView.pagingEnabled = YES;
|
_scrollView.showsHorizontalScrollIndicator = NO;
|
_scrollView.contentSize = CGSizeMake(KScreenW * self.classArray.count , self.frame.size.height-104);
|
_scrollView.delegate = self;
|
[_scrollView scrollRectToVisible:CGRectMake(0, 0, KScreenW, self.frame.size.height-104) animated:NO];
|
// [_cycleScrollView adjustWhenControllerViewWillAppera];
|
[self addSubview:self.scrollView];
|
// _scrollView .alwaysBounceVertical = YES;
|
// _scrollView .alwaysBounceHorizontal = YES;
|
[UIView setAnimationsEnabled:NO];
|
|
|
for (NSInteger index = 0; index <self.classArray.count; index++) {
|
UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
|
//指定布局方式为垂直
|
flow.scrollDirection = UICollectionViewScrollDirectionVertical;
|
flow.minimumLineSpacing = 10;//最小行间距(当垂直布局时是行间距,当水平布局时可以理解为列间距)
|
flow.minimumInteritemSpacing = 10;//两个单元格之间的最小间距
|
|
UICollectionView *collectview = [[UICollectionView alloc]initWithFrame:CGRectMake( KScreenW * index,0, KScreenW, _scrollView.frame.size.height - 49) collectionViewLayout:flow];
|
collectview.tag = collectTag + index;
|
collectview.delegate=self;
|
collectview.dataSource=self;
|
collectview.backgroundColor=kGlobalBackgroundColor;
|
// collectview.backgroundColor = [UIColor orangeColor];
|
collectview .mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
|
[collectview.mj_footer endRefreshingWithNoMoreData];
|
}];
|
collectview.mj_footer.hidden = YES;
|
//注册cell
|
[collectview registerNib:[UINib nibWithNibName:@"recommentCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"recommentCollectionViewCell"];
|
//注册承载明星信息的cell
|
[collectview registerNib:[UINib nibWithNibName:@"StartCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"StartCollectionViewCell"];
|
//广告
|
[collectview registerNib:[UINib nibWithNibName:@"AdCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"AdCollectionViewCell"];
|
//设置轮播图的head
|
[collectview registerNib:[UINib nibWithNibName:@"shufflingCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"shufflingCollectionReusableView"];
|
//设置小广告的foot
|
[collectview registerNib:[UINib nibWithNibName:@"FooterCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterCollectionReusableView"];
|
//设置分类头的head
|
[collectview registerNib:[UINib nibWithNibName:@"HeaderCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderCollectionReusableView"];
|
//设置尾部广点通原生广告的foot
|
[collectview registerNib:[UINib nibWithNibName:@"ADCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"ADCollectionReusableView"];
|
//设置尾部谷歌广告的foot
|
[collectview registerNib:[UINib nibWithNibName:@"GoogleAdCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"GoogleAdCollectionReusableView"];
|
|
[collectview registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"UICollectionReusableView"];
|
|
//推荐视图
|
//先查收看是否有旧的数据,在网络差的时候优先加载旧的数据
|
//给collectionView设置下拉刷新
|
collectview.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
NSLog(@"tag %ld === collectTag %ld ",(long)maintypeNumber + collectTag,(long)collectview.tag);
|
if (collectview == self.collectArray[maintypeNumber]) {
|
// [collectview.mj_header beginRefreshing];
|
[self loadNewData];
|
}
|
}];
|
[self.collectArray addObject:collectview];
|
[_scrollView addSubview:collectview];
|
}
|
[UIView setAnimationsEnabled:YES];
|
|
maintypeNumber = 0;
|
UICollectionView *collectview = self.collectArray[0];
|
collectview.hidden = NO;
|
|
_type_id = self.classArray[0][@"Id"];
|
|
[self loadOldData];
|
[self addSubview:self.noNetworkView];
|
}
|
- (NoNetworkView *)noNetworkView{
|
if (_noNetworkView) {
|
return _noNetworkView;
|
}
|
_noNetworkView = [[NoNetworkView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.vidioGmentControl.frame), KScreenW, 40)];
|
_noNetworkView.hidden = YES;
|
return _noNetworkView;
|
}
|
@end
|