ConsumptionViewController.m 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. //
  2. // ConsumptionViewController.m
  3. // BuguLive
  4. //
  5. // Created by yy on 16/10/18.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "ConsumptionViewController.h"
  9. NS_ENUM(NSInteger, ListClassColl)
  10. {
  11. EClassColl_ListDay, //日榜
  12. EClassColl_ListMonth, //月榜
  13. EClassColl_ListTotal, //总榜
  14. EClassColl_Count,
  15. };
  16. @interface ConsumptionViewController ()<UIScrollViewDelegate,SegmentViewDelegate,MLMSegmentHeadDelegate,ListDayViewControllerDelegate>
  17. {
  18. CGRect _segmentFrame;
  19. UIScrollView *_cScrollView;
  20. NSInteger _startPage;
  21. NSArray *list;
  22. }
  23. @property (nonatomic, strong) MLMSegmentHead *segHead;
  24. @property (nonatomic, strong) MLMSegmentScroll *segScroll;
  25. @property(nonatomic, strong) QMUIButton *listInfoBtn;//榜单介绍
  26. @end
  27. @implementation ConsumptionViewController
  28. - (void)viewDidLoad
  29. {
  30. [super viewDidLoad];
  31. self.view.backgroundColor = kAppSpaceColor3;
  32. [self segmentStyle1];
  33. // [self createScrollView];
  34. self.title = ASLocalizedString(@"魅力榜");
  35. [self setupBackBtnWithBlock:nil];
  36. }
  37. - (void)segmentStyle1 {
  38. list = @[
  39. ASLocalizedString(@" 日榜 "), ASLocalizedString(@" 月榜 "), ASLocalizedString(@" 总榜 "),
  40. ];
  41. _segHead = [[MLMSegmentHead alloc] initWithFrame:CGRectMake(100, 0, SCREEN_WIDTH - 160 , 45) titles:list headStyle:SegmentHeadStyleDefault layoutStyle:MLMSegmentLayoutLeft];
  42. //tab颜色
  43. _segHead.selectColor = kWhiteColor;
  44. _segHead.deSelectColor = [UIColor.whiteColor colorWithAlphaComponent:0.6];
  45. _segHead.btnBgImg = @"bogo_contributeList_rankImgView";
  46. _segHead.fontSize = 15;
  47. _segHead.moreButton_width = 50;//
  48. _segHead.slideHeight = 22;
  49. _segHead.fontScale = 1;//点击后的缩放比例
  50. _segHead.lineHeight = 2;
  51. _segHead.delegate = self;
  52. _segHead.lineScale = .9;
  53. _segHead.headColor = kClearColor;
  54. // CF6;
  55. _segHead.bottomLineHeight = 0;
  56. // _segHead.deSelectColor = [UIColor colorWithRed:0.91 green:0.47 blue:0.62 alpha:1.00];
  57. self.view.backgroundColor = kClearColor;
  58. // CF6;
  59. _segScroll = [[MLMSegmentScroll alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_segHead.frame), SCREEN_WIDTH, SCREEN_HEIGHT-CGRectGetMaxY(_segHead.frame)) vcOrViews:[self vcArr:list.count]];
  60. _segScroll.loadAll = NO;
  61. _segScroll.showIndex = 2;
  62. [MLMSegmentManager associateHead:_segHead withScroll:_segScroll completion:^{
  63. [self.view addSubview:_segHead];
  64. [self.view addSubview:_segScroll];
  65. }];
  66. self.listInfoBtn.frame = CGRectMake(SCREEN_WIDTH - 70 - 15, kStatusBarHeight - 5, 70, 30);
  67. // search.imageEdgeInsets = UIEdgeInsetsMake(6, 6, 6, 6);
  68. self.listInfoBtn.centerY = _segHead.centerY;
  69. [self.listInfoBtn addTarget:self action:@selector(handleSearchEvent) forControlEvents:UIControlEventTouchUpInside];
  70. [self.view addSubview:self.listInfoBtn];
  71. }
  72. -(void)handleSearchEvent{
  73. }
  74. -(void)changeBtnFrom:(UIButton *)btn{
  75. [btn setBackgroundImage:[UIImage imageNamed:@"mg_new_list_concert"] forState:UIControlStateNormal];
  76. }
  77. #pragma mark - 数据源
  78. - (NSArray *)vcArr:(NSInteger)count {
  79. NSMutableArray *arr = [NSMutableArray array];
  80. //日榜
  81. if (!_listDayViewController) {
  82. _listDayViewController = [[ListDayViewController alloc]init];
  83. _listDayViewController.isHiddenTabbar = self.isHiddenTabbar;
  84. _listDayViewController.type = 4;
  85. _listDayViewController.delegate = self;
  86. _listDayViewController.view.frame = CGRectMake(kScreenW * EClassColl_ListDay, 0, kScreenW, _cScrollView.bounds.size.height);
  87. _listDayViewController.view.backgroundColor = kClearColor;
  88. }
  89. [arr addObject:_listDayViewController];
  90. //月榜
  91. if (!_listMonthViewController) {
  92. _listMonthViewController = [[ListDayViewController alloc]init];
  93. _listMonthViewController.isHiddenTabbar = self.isHiddenTabbar;
  94. _listMonthViewController.delegate = self;
  95. _listMonthViewController.type = 5;
  96. _listMonthViewController.view.frame = CGRectMake(kScreenW * EClassColl_ListMonth, 0, kScreenW, _cScrollView.bounds.size.height);
  97. _listMonthViewController.view.backgroundColor = kClearColor;
  98. }
  99. [arr addObject:_listMonthViewController];
  100. //总榜
  101. if (!_listTotalViewController) {
  102. _listTotalViewController = [[ListDayViewController alloc]init];
  103. _listTotalViewController.isHiddenTabbar = self.isHiddenTabbar;
  104. _listTotalViewController.delegate = self;
  105. _listTotalViewController.type = 6;
  106. _listTotalViewController.view.frame = CGRectMake(kScreenW * EClassColl_ListTotal, 0, kScreenW, _cScrollView.bounds.size.height);
  107. _listTotalViewController.view.backgroundColor = kClearColor;
  108. }
  109. [arr addObject:_listTotalViewController];
  110. return arr;
  111. }
  112. - (void)createScrollView
  113. {
  114. //分段视图
  115. NSArray* items = [NSArray arrayWithObjects:ASLocalizedString(@"日榜"), ASLocalizedString(@"月榜"), ASLocalizedString(@"总榜"), nil];
  116. _segmentFrame = CGRectMake(0, 20, 200, 44);
  117. _listSegmentView = [[SegmentView alloc]initWithFrame:_segmentFrame andItems:items andSize:12 border:NO isrankingRist:YES];
  118. _listSegmentView.backgroundColor = kWhiteColor;
  119. _listSegmentView.frame = CGRectMake(0, 0, 200, 44);
  120. _listSegmentView.delegate = self;
  121. // _listSegmentView.segmentControl.tintColor =
  122. [self.view addSubview:_listSegmentView];
  123. if (self.isHiddenTabbar)
  124. {
  125. _cScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, kScreenH-64 - 44)];
  126. }else
  127. {
  128. _cScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, kScreenH-64-49-44)];
  129. }
  130. _cScrollView.backgroundColor = kClearColor;
  131. _cScrollView.contentSize = CGSizeMake(EClassColl_Count*kScreenW, 0);
  132. _cScrollView.pagingEnabled = YES;
  133. _cScrollView.bounces = NO;
  134. _cScrollView.showsHorizontalScrollIndicator = NO;
  135. _cScrollView.delegate = self;
  136. [self.view addSubview:_cScrollView];
  137. _cScrollView.contentOffset = CGPointMake(0, 0);
  138. [_listSegmentView setSelectIndex:0];
  139. //日榜
  140. if (!_listDayViewController) {
  141. _listDayViewController = [[ListDayViewController alloc]init];
  142. _listDayViewController.isHiddenTabbar = self.isHiddenTabbar;
  143. _listDayViewController.type = 1;
  144. _listDayViewController.delegate = self;
  145. _listDayViewController.view.frame = CGRectMake(kScreenW * EClassColl_ListDay, 0, kScreenW, _cScrollView.bounds.size.height);
  146. _listDayViewController.view.backgroundColor = kAppSpaceColor3;
  147. }
  148. [_cScrollView addSubview:_listDayViewController.view];
  149. //月榜
  150. if (!_listMonthViewController) {
  151. _listMonthViewController = [[ListDayViewController alloc]init];
  152. _listMonthViewController.isHiddenTabbar = self.isHiddenTabbar;
  153. _listMonthViewController.delegate = self;
  154. _listMonthViewController.type = 2;
  155. _listMonthViewController.view.frame = CGRectMake(kScreenW * EClassColl_ListMonth, 0, kScreenW, _cScrollView.bounds.size.height);
  156. _listMonthViewController.view.backgroundColor = kAppSpaceColor3;
  157. }
  158. [_cScrollView addSubview:_listMonthViewController.view];
  159. //总榜
  160. if (!_listTotalViewController) {
  161. _listTotalViewController = [[ListDayViewController alloc]init];
  162. _listTotalViewController.isHiddenTabbar = self.isHiddenTabbar;
  163. _listTotalViewController.type = 3;
  164. _listTotalViewController.delegate = self;
  165. _listTotalViewController.view.frame = CGRectMake(kScreenW * EClassColl_ListTotal, 0, kScreenW, _cScrollView.bounds.size.height);
  166. _listTotalViewController.view.backgroundColor = kAppSpaceColor3;
  167. }
  168. [_cScrollView addSubview:_listTotalViewController.view];
  169. }
  170. #pragma mark --SegmentView代理方法
  171. - (void)segmentView:(SegmentView*)segmentView selectIndex:(NSInteger)index
  172. {
  173. [UIView animateWithDuration:0.2f animations:^{
  174. _cScrollView.contentOffset = CGPointMake(_cScrollView.frame.size.width*index, 0);
  175. }];
  176. }
  177. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scroll
  178. {
  179. CGPoint offset = _cScrollView.contentOffset;
  180. NSInteger page = (offset.x + _cScrollView.frame.size.width/2) / _cScrollView.frame.size.width;
  181. // self.listSegmentView.indicatorView.hidden = NO;
  182. [_listSegmentView setSelectIndex:page];
  183. }
  184. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  185. {
  186. CGFloat pageWidth = scrollView.frame.size.width;
  187. NSInteger tmpPage = scrollView.contentOffset.x / pageWidth;
  188. float tmpPage2 = scrollView.contentOffset.x / pageWidth;
  189. NSInteger page = tmpPage2-tmpPage>=0.5 ? tmpPage+1 : tmpPage;
  190. if (_startPage != page)
  191. {
  192. [_listSegmentView setSelectIndex:page];
  193. _startPage = page;
  194. }
  195. }
  196. -(QMUIButton *)listInfoBtn{
  197. if (!_listInfoBtn) {
  198. _listInfoBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  199. [_listInfoBtn setTitle:ASLocalizedString(@"榜单介绍") forState:UIControlStateNormal];
  200. _listInfoBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  201. [_listInfoBtn setImage:[UIImage imageNamed:@"bogo_contribute_list_questionMark"] forState:UIControlStateNormal];
  202. _listInfoBtn.imagePosition = QMUIButtonImagePositionRight;
  203. _listInfoBtn.spacingBetweenImageAndTitle = 5;
  204. [_listInfoBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
  205. _listInfoBtn.alpha = 0.8;
  206. _listInfoBtn.hidden = YES;
  207. }
  208. return _listInfoBtn;
  209. }
  210. @end