VoiceHomeListViewController.m 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  1. //
  2. // NewestViewController.m
  3. // FanweApp
  4. //
  5. // Created by fanwe2014 on 16/7/4.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "VoiceHomeListViewController.h"
  9. #import "cuserModel.h"
  10. #import "LivingModel.h"
  11. #import "HMHotModel.h"
  12. #import "OneSectionCell.h"
  13. #import "WebModels.h"
  14. #import <QMapKit/QMapKit.h>
  15. #import <QMapSearchKit/QMapSearchKit.h>
  16. #import "DistanceModel.h"
  17. #import "NewestItemCell.h"
  18. #import "SDCycleScrollView.h"
  19. #import "AdJumpViewModel.h"
  20. //富豪榜
  21. //#import "MGRecommdHeadView.h"
  22. #import "BogoHomeSubTitleView.h"
  23. #import "MLMSegmentManager.h"
  24. #import "MLMSegmentScroll.h"
  25. #import "MLMSegmentHead.h"
  26. #import "VideoViewController.h"
  27. #import "VoiceListViewController.h"
  28. // 广告图默认滚动时间
  29. #import "BogoSearchViewController.h"
  30. //新的滑动页面
  31. #import <GKPageSmoothView/GKPageSmoothView.h>
  32. #import "GKPageSmoothView.h"
  33. #import "GKDBListView.h"
  34. #import <JXCategoryViewExt/JXCategoryView.h>
  35. #import "BogoJXCategoryView.h"
  36. static float const bannerAutoScrollTimeInterval = 7;
  37. static NSString *firstHeaderViewIdentifier = @"firstHederview";
  38. static NSString *secondHeaderViewIdentifier = @"secondHederview";
  39. @interface VoiceHomeListViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,SDCycleScrollViewDelegate,PushToLiveControllerDelegate,GKPageSmoothViewDataSource, GKPageSmoothViewDelegate, JXCategoryViewDelegate>
  40. @property ( nonatomic,strong) UICollectionView *collectionView; //CollectionView
  41. @property ( nonatomic,strong) UICollectionViewFlowLayout *layout;
  42. @property ( nonatomic,assign) int page;
  43. @property ( nonatomic,assign) int has_next;
  44. @property ( nonatomic,strong) NSMutableArray *dataArray; //数据源
  45. @property ( nonatomic,strong) NSMutableArray *recommandArr; //数据源
  46. @property ( nonatomic,strong) NSMutableArray *titleArray;
  47. //@property ( nonatomic,strong) UIView *NoThingView;
  48. @property (nonatomic, strong) SDCycleScrollView *cycleScrollView;
  49. @property (nonatomic, strong) NSMutableArray *bannArr;
  50. @property(nonatomic, strong) BogoHomeSubTitleView *headView;
  51. @property(nonatomic, strong) QMUIButton *firstBtn;
  52. @property(nonatomic, strong) QMUIButton *secondBtn;
  53. //@property(nonatomic, strong) UILabel *secondL;
  54. //分类导航
  55. @property (nonatomic, assign) MLMSegmentHeadStyle style;
  56. @property (nonatomic, assign) MLMSegmentLayoutStyle mlmLayout;
  57. @property (nonatomic, strong) MLMSegmentHead *segHead;
  58. @property (nonatomic, strong) MLMSegmentScroll *segScroll;
  59. @property (nonatomic, strong) NSMutableArray *itemTitleMutableArray; // 完整的分类标题容器
  60. @property (nonatomic, strong) NSMutableArray *classifiedModelMutableArray; //
  61. @property(nonatomic, strong) NSArray *listArr;
  62. //新滚动
  63. @property (nonatomic, strong) UIView *titleView;
  64. @property (nonatomic, strong) GKPageSmoothView *smoothView;
  65. @property (nonatomic, strong) UIImageView *headerView;
  66. @property (nonatomic, strong) UIView *segmentedView;
  67. @property (nonatomic, strong) BogoJXCategoryView *categoryView;
  68. @property (nonatomic, strong) JXCategoryIndicatorAlignmentLineView *lineView;
  69. @property(nonatomic, strong) NSArray <UIViewController *>*vcArray;
  70. @end
  71. @implementation VoiceHomeListViewController
  72. -(SDCycleScrollView *)cycleScrollView{
  73. if (!_cycleScrollView) {
  74. _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(10, 0, kScreenW - 20, kRealValue(94)) delegate:self placeholderImage:nil];
  75. self.cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
  76. self.cycleScrollView.currentPageDotColor = kAppMainColor; // 自定义分页控件小圆标颜色
  77. self.cycleScrollView.autoScrollTimeInterval = bannerAutoScrollTimeInterval;
  78. self.cycleScrollView.backgroundColor = kWhiteColor;
  79. self.cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
  80. self.cycleScrollView.layer.cornerRadius = 10;
  81. self.cycleScrollView.clipsToBounds = YES;
  82. }
  83. return _cycleScrollView;
  84. }
  85. -(QMUIButton *)firstBtn{
  86. if (!_firstBtn) {
  87. _firstBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  88. _firstBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
  89. _firstBtn.frame = CGRectMake(kRealValue(15), self.cycleScrollView.bottom + kRealValue(10), kScreenW * 0.8, kRealValue(55));
  90. [_firstBtn setTitle:ASLocalizedString(@"Popular recommendation") forState:UIControlStateNormal];
  91. [_firstBtn setTitleColor:[UIColor colorWithHexString:@"#1A1A1A"] forState:UIControlStateNormal];
  92. [_firstBtn setImage:[UIImage imageNamed:@"推荐"] forState:UIControlStateNormal];
  93. _firstBtn.spacingBetweenImageAndTitle = 6;
  94. _firstBtn.imagePosition = QMUIButtonImagePositionLeft;
  95. _firstBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  96. if(self.view.isRTL)
  97. {
  98. _firstBtn.imagePosition = QMUIButtonImagePositionRight;
  99. _firstBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  100. }
  101. }
  102. return _firstBtn;
  103. }
  104. -(QMUIButton *)secondBtn{
  105. if (!_secondBtn) {
  106. _secondBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  107. _secondBtn.frame = CGRectMake(kRealValue(16), 0, kScreenW * 0.5, kRealValue(55));
  108. _secondBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
  109. [_secondBtn setTitle:ASLocalizedString(@"热门主播") forState:UIControlStateNormal];
  110. [_secondBtn setTitleColor:[UIColor colorWithHexString:@"#1A1A1A"] forState:UIControlStateNormal];
  111. [_secondBtn setImage:[UIImage imageNamed:@"推荐"] forState:UIControlStateNormal];
  112. _secondBtn.spacingBetweenImageAndTitle = 2;
  113. _secondBtn.imagePosition = QMUIButtonImagePositionLeft;
  114. // _secondBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  115. // UIControlContentHorizontalAlignmentLeft;
  116. }
  117. return _secondBtn;
  118. }
  119. -(BogoHomeSubTitleView *)headView{
  120. if (!_headView) {
  121. _headView = [[BogoHomeSubTitleView alloc]initWithFrame:CGRectMake(0, self.cycleScrollView.bottom + 5, kScreenW, kRealValue(56))];
  122. }
  123. return _headView;
  124. }
  125. - (void)viewDidLoad
  126. {
  127. [super viewDidLoad];
  128. //左上角添加标题
  129. //Voice room
  130. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, kStatusBarHeight + 15, 200, 44)];
  131. titleLabel.text = @"Voice room";
  132. titleLabel.textColor = [UIColor colorWithHexString:@"#1A1A1A"];
  133. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  134. _dataArray = [[NSMutableArray alloc]init];
  135. _recommandArr = [[NSMutableArray alloc]init];
  136. _titleArray = [[NSMutableArray alloc]init];
  137. [self creatView];
  138. }
  139. - (void)viewWillAppear:(BOOL)animated
  140. {
  141. [super viewWillAppear:animated];
  142. self.navigationController.navigationBar.hidden = YES;
  143. }
  144. - (void)initFWUI
  145. {
  146. [super initFWUI];
  147. }
  148. - (void)initFWData
  149. {
  150. [super initFWData];
  151. [self loadDataWithPage:1];
  152. }
  153. #pragma mark 创建UICollectionView
  154. - (void)creatView
  155. {
  156. self.view.backgroundColor = kWhiteColor;
  157. _layout = [[UICollectionViewFlowLayout alloc]init];
  158. _layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  159. if ([self.types isEqualToString:@"1"]) { _layout.headerReferenceSize=CGSizeMake(self.view.frame.size.width,self.cycleScrollView.height + 10); //设置collectionView头视图的大小
  160. _layout.itemSize = CGSizeMake((kScreenW-30)/2.0f,(kScreenW-30)/2.0f);
  161. }else{
  162. _layout.minimumInteritemSpacing = 3;
  163. _layout.minimumLineSpacing = 3;
  164. _layout.itemSize = CGSizeMake((kScreenW-30)/2,(kScreenW-3)/2);
  165. }
  166. CGRect tmpFrame;
  167. if (_collectionViewFrame.size.height)
  168. {
  169. // tmpFrame = _collectionViewFrame;
  170. tmpFrame = CGRectMake(0, 0, kScreenW, _collectionViewFrame.size.height - self.headView.height);
  171. }
  172. else
  173. {
  174. tmpFrame = CGRectMake(0, 0, kScreenW,self.cycleScrollView.height + (kScreenW-30) / 3.0f + kRealValue(100) + kStatusBarHeight + 44);
  175. // kStatusBarHeight-kTabBarHeight - 22 - 50 + MG_BOTTOM_MARGIN);
  176. }
  177. _collectionView = [[UICollectionView alloc]initWithFrame:tmpFrame collectionViewLayout:_layout];
  178. // [_collectionView.layer insertSublayer:gradientLayer atIndex:0];
  179. // [_collectionView registerClass:[OneSectionCell class] forCellWithReuseIdentifier:@"OneSectionCell"];
  180. [_collectionView registerNib:[UINib nibWithNibName:@"NewestItemCell" bundle:nil] forCellWithReuseIdentifier:@"NewestItemCell"];
  181. [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:firstHeaderViewIdentifier];
  182. [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:secondHeaderViewIdentifier];
  183. _collectionView.backgroundColor = kClearColor;
  184. _collectionView.dataSource = self;
  185. _collectionView.delegate = self;
  186. _collectionView.scrollEnabled = NO;
  187. _collectionView.showsHorizontalScrollIndicator = NO;
  188. [self.view addSubview:_collectionView];
  189. // [_collectionView setBackgroundView:gradientView];
  190. //刷新该页面(主要为了删除最新页已经退出的直播间)
  191. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshHome:) name:@"refreshHome" object:nil];
  192. [BGMJRefreshManager refresh:_collectionView target:self headerRereshAction:@selector(headerReresh) shouldHeaderBeginRefresh:NO footerRereshAction:@selector(footerReresh)];
  193. //
  194. self.itemTitleMutableArray = [NSMutableArray array];
  195. //
  196. _listArr = @[ASLocalizedString(@"推荐"),ASLocalizedString(@"关注")];
  197. //
  198. [self.itemTitleMutableArray addObjectsFromArray:_listArr];
  199. // 动态添加视频分类
  200. for (VideoClassifiedModel *model in [GlobalVariables sharedInstance].appModel.video_classified)
  201. {
  202. [self.itemTitleMutableArray addObject:model.title];
  203. }
  204. self.vcArray = [self vcArr:0];
  205. // _segHead = [[MLMSegmentHead alloc] initWithFrame:CGRectMake(kRealValue(9.5), _collectionView.bottom + kRealValue(15), kScreenW - kRealValue(100), kRealValue(46)) titles:self.itemTitleMutableArray headStyle:SegmentHeadStyleLine layoutStyle:MLMSegmentLayoutLeft];
  206. // //tab颜色
  207. // _segHead.lineScale = 0.3;
  208. //
  209. // _segHead.selectColor = [UIColor colorWithHexString:@"#1A1A1A"];;
  210. // _segHead.delegate = self;
  211. //
  212. // _segHead.fontScale = 1.1;
  213. // // _segHead.lineHeight = 0;
  214. // // _segHead.lineColor = kClearColor;
  215. // _segHead.fontSize = 15;
  216. // _segHead.lineColor = kClearColor;
  217. // _segHead.lineHeight = kRealValue(3);
  218. // _segHead.lineScale = 0.3;
  219. // //滑块设置
  220. // // _segHead.slideHeight = kRealValue(32);
  221. // // _segHead.slideCorner = 4;
  222. // // _segHead.moreButton_width = kRealValue(64);
  223. // // _segHead.singleW_Add = kRealValue(64);
  224. // // _segHead.slideColor = nil;
  225. // // _segHead.slideScale = 1.5;
  226. // _segHead.deSelectColor = [UIColor colorWithHexString:@"#808080"];
  227. // // _segHead.btnBgImg = @"bogo_home_top_bgSelectImg";
  228. // // _segHead.btnBeforeBgImg = @"bogo_home_top_bgBeforeImg";
  229. //
  230. // _segHead.bottomLineHeight = 0;
  231. //
  232. // _segHead.headColor = kClearColor;
  233. // _segHead.deSelectColor = [UIColor colorWithHexString:@"#808080"];
  234. //
  235. // self.view.backgroundColor = kClearColor;
  236. // _segScroll = [[MLMSegmentScroll alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.segHead.frame) + 10, SCREEN_WIDTH,CGRectGetMaxY(_segHead.frame) - kTabBarHeight) vcOrViews:[self vcArr:_listArr.count]];
  237. // _segScroll.loadAll = NO;
  238. // _segScroll.showIndex = 1;
  239. //
  240. // [MLMSegmentManager associateHead:_segHead withScroll:_segScroll completion:^{
  241. // [self.view addSubview:_segHead];
  242. // [self.view addSubview:_segScroll];
  243. // }];
  244. [self viewDidLoad2];
  245. }
  246. #pragma mark - 数据源
  247. - (NSArray *)vcArr:(NSInteger)count
  248. {
  249. NSMutableArray *arr = [NSMutableArray array];
  250. VoiceListViewController *focusVC = [[VoiceListViewController alloc] init];
  251. // focusVC.viewFrame = CGRectMake(0, 0, kScreenW, kScreenH - kTabBarHeight - kRealValue(5) - kRealValue(50) - kTopHeight);
  252. // focusVC.view.frame = CGRectMake(0, 0, kScreenW, kScreenH - kTabBarHeight - kRealValue(5) - kRealValue(50) - kTopHeight);
  253. focusVC.types = @"0";
  254. VoiceListViewController *recommandVC = [[VoiceListViewController alloc] init];
  255. // recommandVC.viewFrame = CGRectMake(0, 0, kScreenW, kScreenH - kTabBarHeight - kRealValue(5) - kRealValue(50) - kTopHeight);
  256. // recommandVC.view.frame = CGRectMake(0, 0, kScreenW, kScreenH - kTabBarHeight - kRealValue(5) - kRealValue(50) - kTopHeight);
  257. recommandVC.types = @"1";
  258. [arr addObject:recommandVC];
  259. [arr addObject:focusVC];
  260. if (self.classifiedModelMutableArray.count > 0)
  261. {
  262. }
  263. self.classifiedModelMutableArray = [GlobalVariables sharedInstance].appModel.video_classified;
  264. for (NSInteger i = 0; i < self.classifiedModelMutableArray.count; ++i)
  265. {
  266. // 服务端下发的分类的在完整的分类容器中的起点
  267. VoiceListViewController *videoVC = [[VoiceListViewController alloc] init];
  268. VideoClassifiedModel * model = [[GlobalVariables sharedInstance].appModel.video_classified objectAtIndex:i];
  269. // videoVC.viewFrame = CGRectMake(0, 0, kScreenW, kScreenH - kTabBarHeight - kRealValue(5) - kRealValue(50) - kTopHeight);
  270. // videoVC.view.frame = CGRectMake(0, 0, kScreenW, kScreenH - kTabBarHeight - kRealValue(5) - kRealValue(50) - kTopHeight);
  271. videoVC.classified_id = model.classified_id;
  272. [arr addObject:videoVC];
  273. }
  274. return arr;
  275. }
  276. #pragma mark ==========================通知==========================
  277. - (void)refreshHome:(NSNotification *)noti
  278. {
  279. if (noti)
  280. {
  281. NSDictionary *tmpDict = (NSDictionary *)noti.object;
  282. NSString *room_id = [tmpDict toString:@"room_id"];
  283. @synchronized (_dataArray)
  284. {
  285. NSMutableArray *tmpArray = _dataArray;
  286. for (LivingModel *model in tmpArray)
  287. {
  288. if (model.room_id == [room_id intValue])
  289. {
  290. [tmpArray removeObject:model];
  291. _dataArray = tmpArray;
  292. [_collectionView reloadData];
  293. return;
  294. }
  295. }
  296. }
  297. }
  298. }
  299. #pragma mark 头部刷新
  300. - (void)headerReresh
  301. {
  302. [self loadDataWithPage:1];
  303. }
  304. #pragma mark 尾部刷新
  305. - (void)footerReresh
  306. {
  307. if (_has_next == 1)
  308. {
  309. _page ++;
  310. [self loadDataWithPage:_page];
  311. }
  312. else
  313. {
  314. [BGMJRefreshManager endRefresh:_collectionView];
  315. }
  316. }
  317. #pragma mark 网络加载
  318. - (void)loadDataFromNet:(int)page{
  319. [self loadDataWithPage:page];
  320. }
  321. - (void)loadDataWithPage:(int)page
  322. {
  323. //加载轮播
  324. NSMutableDictionary *parmDict1 = [NSMutableDictionary dictionary];
  325. [parmDict1 setObject:@"index" forKey:@"ctl"];
  326. [parmDict1 setObject:@"get_voice_banner_list" forKey:@"act"]; [self.httpsManager POSTWithParameters:parmDict1 SuccessBlock:^(NSDictionary *responseJson) {
  327. if ([responseJson toInt:@"status"] == 1)
  328. {
  329. NSArray *bannArr = [responseJson objectForKey:@"data"];
  330. NSMutableArray *tmpMArray = [NSMutableArray array];
  331. self.bannArr = [NSMutableArray array];
  332. for (NSDictionary *dic in bannArr)
  333. {
  334. HMHotBannerModel *bannerModel = [HMHotBannerModel mj_objectWithKeyValues:dic];
  335. [self.bannArr addObject:bannerModel];
  336. [tmpMArray addObject:bannerModel.image];
  337. // [tmpMArray addObject:[dic valueForKey:@"image"]];
  338. }
  339. // 加载延迟
  340. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  341. self.cycleScrollView.imageURLStringsGroup = tmpMArray;
  342. // });
  343. }
  344. } FailureBlock:^(NSError *error) {
  345. }];
  346. //全部主播
  347. self.bannArr = @[];
  348. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  349. if ([self.types isEqualToString:@"1"]){
  350. // || [self.types isEqualToString:@"2"]) {
  351. [parmDict setObject:@"index" forKey:@"ctl"];
  352. [parmDict setObject:@"voice_popularity" forKey:@"act"];
  353. }
  354. [parmDict setObject:[NSString stringWithFormat:@"%d",page] forKey:@"p"];
  355. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  356. {
  357. if ([responseJson toInt:@"status"] == 1)
  358. {
  359. _has_next = [responseJson toInt:@"has_next"];
  360. _page = [responseJson toInt:@"page"];
  361. [_recommandArr removeAllObjects];
  362. //直播数组
  363. NSArray *recommandArr = [responseJson objectForKey:@"data"];
  364. //推荐主播
  365. // NSMutableArray *recommadList = [[NSMutableArray alloc]init];
  366. if (recommandArr && [recommandArr isKindOfClass:[NSArray class]])
  367. {
  368. if (recommandArr.count > 0)
  369. {
  370. for (NSDictionary *dict in recommandArr)
  371. {
  372. LivingModel *model = [LivingModel mj_objectWithKeyValues:dict];
  373. model.xponit = [dict toFloat:@"xpoint"];
  374. model.yponit = [dict toFloat:@"ypoint"];
  375. [self.recommandArr addObject:model];
  376. }
  377. }
  378. }
  379. [_collectionView reloadData];
  380. [self hideNoContentView];
  381. }
  382. [BGMJRefreshManager endRefresh:_collectionView];
  383. } FailureBlock:^(NSError *error)
  384. {
  385. [BGMJRefreshManager endRefresh:_collectionView];
  386. }];
  387. }
  388. // 返回头视图
  389. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
  390. {
  391. //如果是头视图
  392. if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
  393. if (indexPath.section == 0) {
  394. UICollectionReusableView *header=[collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:firstHeaderViewIdentifier forIndexPath:indexPath];
  395. UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 44+StatusBarHeight)];
  396. navView.backgroundColor = kClearColor;
  397. UILabel *titleLab = [[UILabel alloc] init];
  398. titleLab.text = @"Voice room";
  399. titleLab.textColor = [UIColor colorWithHexString:@"#1A1A1A"];
  400. titleLab.font = [UIFont boldSystemFontOfSize:20];
  401. [navView addSubview:titleLab];
  402. [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  403. make.centerY.equalTo(navView).offset(5);
  404. make.left.equalTo(@(10));
  405. make.height.mas_equalTo(44+StatusBarHeight);
  406. }];
  407. /*搜索栏*/
  408. UIButton *searchBtn = [[UIButton alloc] init];
  409. [searchBtn setImage:[UIImage imageNamed:@"habibi_sousuo"] forState:UIControlStateNormal];
  410. [navView addSubview:searchBtn];
  411. UILabel * searchLabel = [[UILabel alloc] init];
  412. searchLabel.text = ASLocalizedString(@"搜索");
  413. searchLabel.font = [UIFont systemFontOfSize:12];
  414. searchLabel.textColor = [UIColor colorWithHexString:@"#333333"];
  415. [searchBtn addSubview:searchLabel];
  416. UIButton *startLive = [[UIButton alloc] init];
  417. [startLive setImage:[UIImage imageNamed:@"进入房间"] forState:UIControlStateNormal];
  418. [startLive addTarget:self action:@selector(handleLiveEvent) forControlEvents:UIControlEventTouchUpInside];
  419. [navView addSubview:startLive];
  420. UIButton *paihangBtn = [[UIButton alloc] init];
  421. [paihangBtn setImage:[UIImage imageNamed:@"hbibi_paihagnbang"] forState:UIControlStateNormal];
  422. [navView addSubview:paihangBtn];
  423. [paihangBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  424. make.right.equalTo(startLive.mas_left).offset(kRealValue(-10));
  425. make.size.height.equalTo(@kRealValue(30));
  426. make.size.width.equalTo(@kRealValue(30));
  427. make.centerY.equalTo(startLive);
  428. }];
  429. [searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  430. // make.right.equalTo(paihangBtn.mas_left).offset(kRealValue(-10));
  431. // make.size.height.equalTo(@kRealValue(28));
  432. // make.size.width.equalTo(@kRealValue(140));
  433. // make.centerY.equalTo(startLive);
  434. make.right.mas_equalTo(paihangBtn.mas_left).mas_offset(-10);
  435. make.centerY.mas_equalTo(startLive);
  436. make.width.mas_equalTo(70);
  437. make.height.mas_equalTo(28);
  438. }];
  439. [searchLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  440. make.centerY.mas_equalTo(searchBtn);
  441. make.centerX.mas_equalTo(searchBtn).mas_offset(10);
  442. }];
  443. [startLive mas_makeConstraints:^(MASConstraintMaker *make) {
  444. make.right.equalTo(navView).offset(kRealValue(-10));
  445. make.size.height.equalTo(@kRealValue(30));
  446. make.size.width.equalTo(@kRealValue(30));
  447. make.centerY.equalTo(titleLab);
  448. }];
  449. [searchBtn addTarget:self action:@selector(clickSearch:) forControlEvents:UIControlEventTouchUpInside];
  450. [paihangBtn addTarget:self action:@selector(clickPaihang) forControlEvents:UIControlEventTouchUpInside];
  451. /*搜索栏结束*/
  452. [navView addSubview:titleLab];
  453. [header addSubview:navView];
  454. // [self.view addSubview:baseView];
  455. self.cycleScrollView.top = 44+StatusBarHeight;
  456. //头视图添加view
  457. // if (!_firstL) {
  458. // self.firstBtn.frame = CGRectMake(kRealValue(15), self.headView.bottom, kScreenW * 0.5, kRealValue(55));
  459. self.firstBtn.top = self.cycleScrollView.bottom + kRealValue(10);
  460. self.secondBtn.top = self.cycleScrollView.bottom;
  461. [header addSubview:self.cycleScrollView];
  462. [header addSubview:self.firstBtn];
  463. if(self.view.isRTL)
  464. {
  465. [_firstBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  466. make.top.equalTo(self.headView.mas_bottom).offset(kRealValue(44));
  467. make.leading.equalTo(self.headView).offset(kRealValue(-15));
  468. }];
  469. }
  470. if (kIsCheckingVersion() || ![self.types isEqualToString:@"1"]) {
  471. self.headView.hidden = self.firstBtn.hidden = YES;
  472. }
  473. return header;
  474. }
  475. else if (indexPath.section == 1) {
  476. UICollectionReusableView *header=[collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:secondHeaderViewIdentifier forIndexPath:indexPath];
  477. //头视图添加view
  478. // if (!_secondL) {
  479. [header addSubview:self.secondBtn];
  480. // if (![self.types isEqualToString:@"1"]) {
  481. // self.secondBtn.hidden = YES;
  482. // self.cycleScrollView.hidden = YES;
  483. // }
  484. // }
  485. return header;
  486. }
  487. }
  488. return nil;
  489. }
  490. #pragma mark UICollectionViewDataSource UICollectionViewDelegate
  491. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  492. {
  493. return 1;
  494. // FWNewEstTab_Count;
  495. }
  496. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
  497. if (![self.types isEqualToString:@"1"]) {
  498. return CGSizeMake(0, 0);;
  499. // return CGSizeMake(kScreenW, kRealValue(120));
  500. }
  501. if (section == 0) {
  502. if (kIsCheckingVersion() || ![self.types isEqualToString:@"1"]) {
  503. return CGSizeMake(0, 0);
  504. }
  505. return CGSizeMake(kScreenW, self.firstBtn.bottom - 10);
  506. }
  507. return CGSizeMake(kScreenW, self.secondBtn.bottom - 10);
  508. }
  509. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  510. {
  511. if (section == 0) {
  512. if (![self.types isEqualToString:@"1"]) {
  513. return 0;
  514. }
  515. if(self.recommandArr.count > 3)
  516. {
  517. return 3;
  518. }
  519. return self.recommandArr.count;
  520. }else{
  521. return _dataArray.count;
  522. }
  523. }
  524. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  525. {
  526. if (indexPath.section == 0) {
  527. NewestItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NewestItemCell" forIndexPath:indexPath];
  528. cell.backgroundColor = [UIColor whiteColor];
  529. if (_recommandArr.count > 0) {
  530. LivingModel *LModel = _recommandArr[indexPath.row];
  531. [cell setCellContent:LModel Type:[self.types intValue]];
  532. }
  533. return cell;
  534. }else{
  535. NewestItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NewestItemCell" forIndexPath:indexPath];
  536. cell.backgroundColor = [UIColor whiteColor];
  537. if (_dataArray.count > 0) {
  538. LivingModel *LModel = _dataArray[indexPath.row];
  539. [cell setCellContent:LModel Type:[self.types intValue]];
  540. }
  541. return cell;
  542. }
  543. }
  544. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  545. // if ([_types isEqualToString:@"1"] || [_types isEqualToString:@"2"]) {
  546. return CGSizeMake((kScreenW-50)/3.0f, (kScreenW-30) / 3.0f + kRealValue(32));
  547. // }
  548. // return CGSizeMake((kScreenW-3)/2, (kScreenW-3)/2 + kRealValue(32));
  549. }
  550. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  551. return 0;
  552. }
  553. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  554. {
  555. if ([_types isEqualToString:@"1"] ) {
  556. return UIEdgeInsetsMake(10, 10, 10, 10);
  557. }
  558. if ( [_types isEqualToString:@"2"]) {
  559. return UIEdgeInsetsMake(0, 10, 10, 10);
  560. }
  561. return UIEdgeInsetsMake(0, 0, 0, 0);
  562. }
  563. #pragma mark 跳转到在线直播
  564. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  565. {
  566. LivingModel *model;
  567. if (indexPath.section == 0) {
  568. model = _recommandArr[indexPath.row];
  569. }else{
  570. model = _dataArray[indexPath.row];
  571. }
  572. if (self.delegate)
  573. {
  574. if ([self.delegate respondsToSelector:@selector(pushToLiveController:modelArr:isFirstJump:)])
  575. {
  576. [self.delegate pushToLiveController:model modelArr:self.dataArray isFirstJump:YES];
  577. }
  578. }
  579. }
  580. #pragma mark 跳转到直播的tableView
  581. - (void)GotoNextViewWithBlockTag:(int)tag
  582. {
  583. cuserModel *model = _titleArray[tag];
  584. if (self.delegate)
  585. {
  586. if ([self.delegate respondsToSelector:@selector(pushToNextControllerWithModel:)])
  587. {
  588. [self.delegate pushToNextControllerWithModel:model];
  589. }
  590. }
  591. }
  592. -(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
  593. HMHotBannerModel *hotBannerModel = [self.bannArr objectAtIndex:index];
  594. if ([AdJumpViewModel adToOthersWith:hotBannerModel])
  595. {
  596. [[AppDelegate sharedAppDelegate]pushViewController:[AdJumpViewModel adToOthersWith:hotBannerModel] animated:YES];
  597. }
  598. }
  599. - (void)viewDidLoad2 {
  600. [self.view addSubview:self.smoothView];
  601. [self.smoothView mas_makeConstraints:^(MASConstraintMaker *make) {
  602. make.top.equalTo(self.view);
  603. make.left.and.right.and.bottom.equalTo(self.view);
  604. }];
  605. self.smoothView.listCollectionView.backgroundColor = kClearColor;
  606. self.categoryView.contentScrollView = self.smoothView.listCollectionView;
  607. [self.smoothView reloadData];
  608. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(pullDownToRefresh)];
  609. _smoothView.listCollectionView.mj_header = header;
  610. // [self.smoothView setCurrentIndex:1]
  611. }
  612. #pragma mark - GKPageSmoothViewDataSource
  613. - (UIView *)headerViewInSmoothView:(GKPageSmoothView *)smoothView {
  614. // self.collectionView.backgroundColor = kRedColor;
  615. //添加一个从上到下的渐变视图 #FBE2FF - #DFFFF9、
  616. CAGradientLayer *gradientLayer = [CAGradientLayer layer];
  617. gradientLayer.frame = CGRectMake(0, 0, kScreenW, 250);
  618. gradientLayer.colors = @[(__bridge id)[UIColor colorWithHexString:@"#FBE2FF"].CGColor, (__bridge id)[UIColor colorWithHexString:@"#DFFFF9"].CGColor];
  619. gradientLayer.startPoint = CGPointMake(0, 0);
  620. gradientLayer.endPoint = CGPointMake(0, 1);
  621. //把gradientLayer加到_collectionView最底部
  622. // UIView *gradientView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 250)];
  623. UIView *view = [[UIView alloc] initWithFrame:self.collectionView.bounds];
  624. // view.backgroundColor = kYellowColor;
  625. [view addSubview:self.collectionView];
  626. [view.layer insertSublayer:gradientLayer atIndex:0];
  627. return view;
  628. }
  629. - (UIView *)segmentedViewInSmoothView:(GKPageSmoothView *)smoothView {
  630. return self.segmentedView;
  631. }
  632. - (NSInteger)numberOfListsInSmoothView:(GKPageSmoothView *)smoothView {
  633. return self.categoryView.titles.count;
  634. }
  635. - (id<GKPageSmoothListViewDelegate>)smoothView:(GKPageSmoothView *)smoothView initListAtIndex:(NSInteger)index {
  636. return self.vcArray[index];
  637. GKDBListView *listView = [GKDBListView new];
  638. return listView;
  639. // GKBaseListViewController *listVC = [[GKBaseListViewController alloc] initWithListType:index];
  640. // listVC.shouldLoadData = YES;
  641. // return listVC;
  642. }
  643. #pragma mark - GKPageSmoothViewDelegate
  644. - (void)smoothView:(GKPageSmoothView *)smoothView listScrollViewDidScroll:(UIScrollView *)scrollView contentOffset:(CGPoint)contentOffset {
  645. if (smoothView.isOnTop) return;
  646. // 导航栏显隐
  647. CGFloat offsetY = contentOffset.y;
  648. CGFloat alpha = 0;
  649. if (offsetY <= 0) {
  650. alpha = 0;
  651. }else if (offsetY > 60) {
  652. alpha = 1;
  653. [self changeTitle:YES];
  654. }else {
  655. alpha = offsetY / 60;
  656. [self changeTitle:NO];
  657. }
  658. }
  659. - (void)smoothViewDragBegan:(GKPageSmoothView *)smoothView {
  660. if (smoothView.isOnTop) return;
  661. }
  662. - (void)smoothViewDragEnded:(GKPageSmoothView *)smoothView isOnTop:(BOOL)isOnTop {
  663. // titleView已经显示,不作处理
  664. }
  665. - (void)changeTitle:(BOOL)isShow {
  666. }
  667. #pragma mark - JXCategoryViewDelegate
  668. - (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
  669. // [self.smoothView showingOnTop];
  670. }
  671. #pragma mark - 懒加载
  672. - (UIView *)titleView {
  673. if (!_titleView) {
  674. _titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 100, 44.0f)];
  675. UIImage *image = [UIImage imageNamed:@"db_title"];
  676. UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
  677. imgView.frame = CGRectMake(0, 0, 44.0f * image.size.width / image.size.height, 44.0f);
  678. [_titleView addSubview:imgView];
  679. }
  680. return _titleView;
  681. }
  682. - (GKPageSmoothView *)smoothView {
  683. if (!_smoothView) {
  684. _smoothView = [[GKPageSmoothView alloc] initWithDataSource:self];
  685. // _smoothView.defaultSelectedIndex = 1;
  686. // _smoothView.currentIndex = 1;
  687. _smoothView.backgroundColor = kClearColor;
  688. _smoothView.delegate = self;
  689. _smoothView.ceilPointHeight = 0;
  690. // _smoothView.bottomHover = YES;
  691. // _smoothView.allowDragBottom = YES;
  692. // _smoothView.allowDragScroll = YES;
  693. // 解决与返回手势滑动冲突
  694. // _smoothView.listCollectionView.gk_openGestureHandle = YES;
  695. _smoothView.holdUpScrollView = YES;
  696. }
  697. return _smoothView;
  698. }
  699. - (void)pullDownToRefresh
  700. {
  701. }
  702. - (UIImageView *)headerView {
  703. if (!_headerView) {
  704. UIImage *image = [UIImage imageNamed:@"douban"];
  705. _headerView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
  706. _headerView.image = image;
  707. }
  708. return _headerView;
  709. }
  710. - (UIView *)segmentedView {
  711. if (!_segmentedView) {
  712. _segmentedView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 60)];
  713. _segmentedView.backgroundColor = [UIColor whiteColor];
  714. [_segmentedView addSubview:self.categoryView];
  715. // UIView *topView = [UIView new];
  716. // topView.backgroundColor = [UIColor lightGrayColor];
  717. // topView.layer.cornerRadius = 3;
  718. // topView.layer.masksToBounds = YES;
  719. // [_segmentedView addSubview:topView];
  720. // [topView mas_makeConstraints:^(MASConstraintMaker *make) {
  721. // make.top.equalTo(self->_segmentedView).offset(5);
  722. // make.centerX.equalTo(self->_segmentedView);
  723. // make.width.mas_equalTo(60);
  724. // make.height.mas_equalTo(6);
  725. // }];
  726. }
  727. return _segmentedView;
  728. }
  729. - (BogoJXCategoryView *)categoryView {
  730. if (!_categoryView) {
  731. _categoryView = [[BogoJXCategoryView alloc] initWithFrame:CGRectMake(0, 10, self.view.frame.size.width, 40)];
  732. _categoryView.backgroundColor = UIColor.whiteColor;
  733. _categoryView.averageCellSpacingEnabled = NO;
  734. _categoryView.contentEdgeInsetLeft = 16;
  735. _categoryView.delegate = self;
  736. _categoryView.titles = self.itemTitleMutableArray;
  737. _categoryView.titleFont = [UIFont systemFontOfSize:16];
  738. _categoryView.titleColor = UIColor.grayColor;
  739. _categoryView.titleSelectedColor = UIColor.blackColor;
  740. _categoryView.subTitleFont = [UIFont systemFontOfSize:11];
  741. _categoryView.subTitleColor = UIColor.grayColor;
  742. _categoryView.subTitleSelectedColor = UIColor.grayColor;
  743. _categoryView.positionStyle = JXCategorySubTitlePositionStyle_Right;
  744. _categoryView.alignStyle = JXCategorySubTitleAlignStyle_Top;
  745. _categoryView.cellSpacing = 30;
  746. _categoryView.cellWidthIncrement = 0;
  747. _categoryView.ignoreSubTitleWidth = YES;
  748. JXCategoryIndicatorLineView *lineView = [JXCategoryIndicatorLineView new];
  749. lineView.indicatorColor = UIColor.blackColor;
  750. _categoryView.indicators = @[self.lineView];
  751. // _categoryView.contentScrollView = self.smoothView.listCollectionView;
  752. }
  753. return _categoryView;
  754. }
  755. - (JXCategoryIndicatorAlignmentLineView *)lineView {
  756. if (!_lineView) {
  757. _lineView = [JXCategoryIndicatorAlignmentLineView new];
  758. _lineView.indicatorColor = UIColor.blackColor;
  759. }
  760. return _lineView;
  761. }
  762. -(void)clickSearch:(UITapGestureRecognizer *)sender{
  763. // SSearchVC *searchVC = [[SSearchVC alloc]init];
  764. // searchVC.searchType = @"0";
  765. // [[AppDelegate sharedAppDelegate] pushViewController:searchVC animated:YES];
  766. BogoSearchViewController *searchVC = [[BogoSearchViewController alloc]initWithNibName:@"BogoSearchViewController" bundle:[NSBundle mainBundle]];
  767. [[AppDelegate sharedAppDelegate] pushViewController:searchVC animated:YES];
  768. }
  769. - (void)clickPaihang {
  770. LeaderboardViewController *lbVCtr = [[LeaderboardViewController alloc] init];
  771. lbVCtr.isHiddenTabbar = YES;
  772. [[AppDelegate sharedAppDelegate]pushViewController:lbVCtr animated:YES];
  773. }
  774. - (void)handleLiveEvent {
  775. if(self.topViewdelegate && [self.topViewdelegate respondsToSelector:@selector(clickLiveBtn)]) {
  776. [self.topViewdelegate clickLiveBtn];
  777. }
  778. }
  779. @end