GKBasePageViewController.m 36 KB

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