ContributionViewController.m 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. //
  2. // ContributionViewController.m
  3. // BuguLive
  4. //
  5. // Created by yy on 16/10/18.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "ContributionViewController.h"
  9. NS_ENUM(NSInteger, ContriClassColl)
  10. {
  11. EClassColl_ContriDay, //日榜
  12. EClassColl_ContriMonth, //月榜
  13. EClassColl_ContriTotal, //总榜
  14. EClass_Count,
  15. };
  16. @interface ContributionViewController ()<UIScrollViewDelegate,SegmentViewDelegate,MLMSegmentHeadDelegate,ListDayViewControllerDelegate>
  17. {
  18. CGRect _segmentFrame;
  19. UIScrollView *_bScrollView;
  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 ContributionViewController
  28. - (void)viewDidLoad
  29. {
  30. [super viewDidLoad];
  31. self.view.backgroundColor = kAppSpaceColor3;
  32. [self segmentStyle1];
  33. self.title = ASLocalizedString(@"贡献榜");
  34. [self setupBackBtnWithBlock:nil];
  35. }
  36. - (void)segmentStyle1 {
  37. list = @[
  38. ASLocalizedString(@" 日榜 "), ASLocalizedString(@" 月榜 "), ASLocalizedString(@" 总榜 "),
  39. ];
  40. _segHead = [[MLMSegmentHead alloc] initWithFrame:CGRectMake(100, 0, SCREEN_WIDTH - 160 , 45) titles:list headStyle:SegmentHeadStyleDefault layoutStyle:MLMSegmentLayoutLeft];
  41. //tab颜色
  42. _segHead.selectColor = kWhiteColor;
  43. _segHead.deSelectColor = [UIColor.whiteColor colorWithAlphaComponent:0.6];
  44. // [UIColor colorWithHexString:@"#999999"];
  45. _segHead.fontSize = 15;
  46. _segHead.moreButton_width = 50;//
  47. _segHead.fontScale = 1;//点击后的缩放比例
  48. _segHead.lineHeight = 2;
  49. _segHead.delegate = self;
  50. _segHead.slideHeight = 22;
  51. _segHead.lineScale = .9;
  52. _segHead.headColor = kClearColor;
  53. _segHead.btnBgImg = @"bogo_contributeList_rankImgView";
  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)changeBtnFrom:(UIButton *)btn{
  73. [btn setBackgroundImage:[UIImage imageNamed:@"mg_new_list_concert"] forState:UIControlStateNormal];
  74. }
  75. -(void)handleSearchEvent{
  76. }
  77. #pragma mark - 数据源
  78. - (NSArray *)vcArr:(NSInteger)count {
  79. NSMutableArray *arr = [NSMutableArray array];
  80. //日榜
  81. if (!_ContriDayViewController) {
  82. _ContriDayViewController = [[ListDayViewController alloc]init];
  83. _ContriDayViewController.isHiddenTabbar = self.isHiddenTabbar;
  84. _ContriDayViewController.type = 1;
  85. _ContriDayViewController.delegate = self;
  86. _ContriDayViewController.view.frame = CGRectMake(kScreenW * EClassColl_ContriDay, 0, kScreenW, _bScrollView.bounds.size.height);
  87. _ContriDayViewController.view.backgroundColor = kClearColor;
  88. }
  89. [arr addObject:_ContriDayViewController];
  90. //月榜
  91. if (!_ContriMonthViewController) {
  92. _ContriMonthViewController = [[ListDayViewController alloc]init];
  93. _ContriMonthViewController.isHiddenTabbar = self.isHiddenTabbar;
  94. _ContriMonthViewController.type = 2;
  95. _ContriMonthViewController.delegate = self;
  96. _ContriMonthViewController.view.frame = CGRectMake(kScreenW * EClassColl_ContriMonth, 0, kScreenW, _bScrollView.bounds.size.height);
  97. _ContriMonthViewController.view.backgroundColor = kClearColor;
  98. }
  99. [arr addObject:_ContriMonthViewController];
  100. //总榜
  101. if (!_ContriTotalViewController) {
  102. _ContriTotalViewController = [[ListDayViewController alloc]init];
  103. _ContriTotalViewController.isHiddenTabbar = self.isHiddenTabbar;
  104. _ContriTotalViewController.type = 3;
  105. _ContriTotalViewController.delegate = self;
  106. _ContriTotalViewController.view.frame = CGRectMake(kScreenW * EClassColl_ContriTotal, 0, kScreenW, _bScrollView.bounds.size.height);
  107. _ContriTotalViewController.view.backgroundColor = kClearColor;
  108. }
  109. [arr addObject:_ContriTotalViewController];
  110. return arr;
  111. }
  112. - (void)createScroll
  113. {
  114. //分段视图
  115. NSArray* items = [NSArray arrayWithObjects:ASLocalizedString(@"日榜"), ASLocalizedString(@"月榜"), ASLocalizedString(@"总榜"), nil];
  116. _segmentFrame = CGRectMake(kScreenW/8, 20, kScreenW - 40, 44);
  117. _contriSegmentView = [[SegmentView alloc]initWithFrame:_segmentFrame andItems:items andSize:12 border:NO isrankingRist:YES];
  118. _contriSegmentView.backgroundColor = kWhiteColor;
  119. _contriSegmentView.frame = CGRectMake(20, 20, kScreenW - 40, 44);
  120. _contriSegmentView.delegate = self;
  121. [self.view addSubview:_contriSegmentView];
  122. if (self.isHiddenTabbar)
  123. {
  124. _bScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, kScreenH-64 - 44)];
  125. }else
  126. {
  127. _bScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, kScreenH-64-49-44)];
  128. }
  129. _bScrollView.backgroundColor = kClearColor;
  130. _bScrollView.contentSize = CGSizeMake(EClass_Count*kScreenW, 0);
  131. _bScrollView.pagingEnabled = YES;
  132. _bScrollView.bounces = NO;
  133. _bScrollView.showsHorizontalScrollIndicator = NO;
  134. _bScrollView.delegate = self;
  135. [self.view addSubview:_bScrollView];
  136. _bScrollView.contentOffset = CGPointMake(0, 0);
  137. [_contriSegmentView setSelectIndex:0];
  138. //日榜
  139. if (!_ContriDayViewController) {
  140. _ContriDayViewController = [[ListDayViewController alloc]init];
  141. _ContriDayViewController.isHiddenTabbar = self.isHiddenTabbar;
  142. _ContriDayViewController.type = 1;
  143. _ContriDayViewController.view.frame = CGRectMake(kScreenW * EClassColl_ContriDay, 0, kScreenW, _bScrollView.bounds.size.height);
  144. _ContriDayViewController.view.backgroundColor = kAppSpaceColor3;
  145. }
  146. [_bScrollView addSubview:_ContriDayViewController.view];
  147. //月榜
  148. if (!_ContriMonthViewController) {
  149. _ContriMonthViewController = [[ListDayViewController alloc]init];
  150. _ContriMonthViewController.isHiddenTabbar = self.isHiddenTabbar;
  151. _ContriMonthViewController.type = 2;
  152. _ContriMonthViewController.view.frame = CGRectMake(kScreenW * EClassColl_ContriMonth, 0, kScreenW, _bScrollView.bounds.size.height);
  153. _ContriMonthViewController.view.backgroundColor = kAppSpaceColor3;
  154. }
  155. [_bScrollView addSubview:_ContriMonthViewController.view];
  156. //总榜
  157. if (!_ContriTotalViewController) {
  158. _ContriTotalViewController = [[ListDayViewController alloc]init];
  159. _ContriTotalViewController.isHiddenTabbar = self.isHiddenTabbar;
  160. _ContriTotalViewController.type = 3;
  161. _ContriTotalViewController.view.frame = CGRectMake(kScreenW * EClassColl_ContriTotal, 0, kScreenW, _bScrollView.bounds.size.height);
  162. _ContriTotalViewController.view.backgroundColor = kAppSpaceColor3;
  163. }
  164. [_bScrollView addSubview:_ContriTotalViewController.view];
  165. }
  166. #pragma mark --SegmentView代理方法
  167. - (void)segmentView:(SegmentView*)segmentView selectIndex:(NSInteger)index
  168. {
  169. [UIView animateWithDuration:0.2f animations:^{
  170. _bScrollView.contentOffset = CGPointMake(_bScrollView.frame.size.width*index, 20);
  171. }];
  172. }
  173. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scroll
  174. {
  175. CGPoint offset = _bScrollView.contentOffset;
  176. NSInteger page = (offset.x + _bScrollView.frame.size.width/2) / _bScrollView.frame.size.width;
  177. // self.contriSegmentView.indicatorView.hidden = NO;
  178. [_contriSegmentView setSelectIndex:page];
  179. }
  180. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  181. {
  182. CGFloat pageWidth = scrollView.frame.size.width;
  183. NSInteger tmpPage = scrollView.contentOffset.x / pageWidth;
  184. float tmpPage2 = scrollView.contentOffset.x / pageWidth;
  185. NSInteger page = tmpPage2-tmpPage>=0.5 ? tmpPage+1 : tmpPage;
  186. if (_startPage != page)
  187. {
  188. [_contriSegmentView setSelectIndex:page];
  189. _startPage = page;
  190. }
  191. }
  192. -(QMUIButton *)listInfoBtn{
  193. if (!_listInfoBtn) {
  194. _listInfoBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  195. [_listInfoBtn setTitle:ASLocalizedString(@"榜单介绍") forState:UIControlStateNormal];
  196. _listInfoBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  197. [_listInfoBtn setImage:[UIImage imageNamed:@"bogo_contribute_list_questionMark"] forState:UIControlStateNormal];
  198. _listInfoBtn.imagePosition = QMUIButtonImagePositionRight;
  199. _listInfoBtn.spacingBetweenImageAndTitle = 5;
  200. [_listInfoBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
  201. _listInfoBtn.alpha = 0.8;
  202. _listInfoBtn.hidden = YES;
  203. }
  204. return _listInfoBtn;
  205. }
  206. @end