ContributionListViewController.m 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. //
  2. // ContributionListViewController.m
  3. // BuguLive
  4. //
  5. // Created by fanwe2014 on 16/6/7.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "ContributionListViewController.h"
  9. #import "SHomePageVC.h"
  10. #import "LeaderboardViewController.h"
  11. #import "SContributionView.h"
  12. #import "BogoRankHeadGifView.h"
  13. @interface ContributionListViewController ()<SegmentViewDelegate,ContriButionDeleGate,UIScrollViewDelegate>
  14. @property (nonatomic, strong) UIScrollView *cScrollView;
  15. @property (nonatomic, assign) NSInteger startPage;
  16. @property (nonatomic, assign) CGRect segmentFrame;
  17. @property (nonatomic, strong) UITableView *myTableview;
  18. @property (nonatomic, strong) SContributionView *contributionV1; //当前排行
  19. @property (nonatomic, strong) SContributionView *contributionV2; //累计排行
  20. @property(nonatomic, strong) UIImageView *bgImgView;
  21. @property(nonatomic, strong) UILabel *titleL;
  22. @property(nonatomic, strong) UIButton *backBtn;
  23. @property(nonatomic, strong) UIImageView *segBgView;
  24. @end
  25. @implementation ContributionListViewController
  26. - (void)viewDidLoad
  27. {
  28. [super viewDidLoad];
  29. SUS_WINDOW.window_Tap_Ges.enabled = NO;
  30. SUS_WINDOW.window_Pan_Ges.enabled = NO;
  31. [self.view addSubview:self.bgImgView];
  32. self.navigationItem.leftBarButtonItem=[UIBarButtonItem itemWithTarget:self action:@selector(backClick) image:@"com_arrow_vc_back" highImage:@"com_arrow_vc_back"];
  33. self.title = [NSString stringWithFormat:ASLocalizedString(@"%@贡献榜"),self.BuguLive.appModel.ticket_name];
  34. self.view.backgroundColor = kWhiteColor;
  35. self.titleL = [[UILabel alloc]initWithFrame:CGRectMake(0, kStatusBarHeight, kScreenW * 0.6, kRealValue(40))];
  36. self.titleL.text = self.title;
  37. self.titleL.textAlignment = NSTextAlignmentCenter;
  38. self.titleL.centerX = kScreenW / 2;
  39. self.titleL.textColor = kWhiteColor;
  40. self.backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  41. [self.backBtn setImage:[UIImage imageNamed:@"back_w"] forState:UIControlStateNormal];
  42. self.backBtn.frame = CGRectMake(0, kStatusBarHeight, kRealValue(30), kRealValue(30));
  43. self.backBtn.centerY = self.titleL.centerY;
  44. [self.backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  45. if ([self.type intValue] == 1)
  46. {
  47. NSArray* items = [NSArray arrayWithObjects:ASLocalizedString(@"当天排行"), ASLocalizedString(@"累计排行"), nil];
  48. _segmentFrame = CGRectMake(0,self.titleL.bottom + kRealValue(10), kScreenW, kRealValue(40));
  49. _listSegmentView = [[SegmentView alloc]initWithFrame:_segmentFrame andItems:items andSize:12 border:NO isrankingRist:NO];
  50. _listSegmentView.backgroundColor = kClearColor;
  51. _listSegmentView.frame = _segmentFrame;
  52. _listSegmentView.delegate = self;
  53. [self.view addSubview:self.segBgView];
  54. [self.view addSubview:_listSegmentView];
  55. }
  56. _cScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_listSegmentView.frame), kScreenW,kScreenH-kTopHeight-_listSegmentView.height)];
  57. _cScrollView.backgroundColor = kClearColor;
  58. if ([self.type intValue] == 1)
  59. {
  60. _cScrollView.contentSize = CGSizeMake(2*kScreenW, 0);
  61. }else
  62. {
  63. _cScrollView.contentSize = CGSizeMake(kScreenW, 0);
  64. }
  65. _cScrollView.pagingEnabled = YES;
  66. _cScrollView.bounces = NO;
  67. _cScrollView.showsHorizontalScrollIndicator = NO;
  68. _cScrollView.delegate = self;
  69. [self.view addSubview:_cScrollView];
  70. [_listSegmentView setSelectIndex:0];
  71. if ([self.type intValue] == 1)
  72. {
  73. //当日排行
  74. if (!_contributionV1)
  75. {
  76. _contributionV1 = [[SContributionView alloc]initWithFrame:CGRectMake(0, 0,_cScrollView.width, _cScrollView.height) andDataType:1 andUserId:self.user_id andLiveRoomId:self.liveAVRoomId];
  77. _contributionV1.CDelegate = self;
  78. _contributionV1.backgroundColor = kClearColor;
  79. [_cScrollView addSubview:_contributionV1];
  80. }
  81. }
  82. //累计排行
  83. if (!_contributionV2)
  84. {
  85. if ([self.type intValue] == 1)
  86. {
  87. _contributionV2 = [[SContributionView alloc]initWithFrame:CGRectMake(kScreenW, 0,_cScrollView.width, _cScrollView.height) andDataType:2 andUserId:self.user_id andLiveRoomId:self.liveAVRoomId];
  88. }else
  89. {
  90. _contributionV2 = [[SContributionView alloc]initWithFrame:CGRectMake(0, 0,_cScrollView.width, _cScrollView.height) andDataType:2 andUserId:self.user_id andLiveRoomId:self.liveAVRoomId];
  91. }
  92. _contributionV2.backgroundColor = kClearColor;
  93. _contributionV2.CDelegate = self;
  94. [_cScrollView addSubview:_contributionV2];
  95. }
  96. if ([self.type intValue]== 1)
  97. {
  98. [_cScrollView scrollRectToVisible:CGRectMake(0, 0, _cScrollView.width, CGRectGetHeight(_cScrollView.frame)) animated:NO];
  99. }else
  100. {
  101. [_cScrollView scrollRectToVisible:CGRectMake(_cScrollView.width, 0, _cScrollView.width, CGRectGetHeight(_cScrollView.frame)) animated:NO];
  102. _cScrollView.alwaysBounceHorizontal = NO;
  103. }
  104. if ([self.BuguLive.appModel.open_ranking_list intValue] ==1)
  105. {
  106. UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
  107. rightButton.frame = CGRectMake(0, 5, 50, 30);
  108. rightButton.tag = 1;
  109. rightButton.titleLabel.font = [UIFont systemFontOfSize:18];
  110. [rightButton setTitle:ASLocalizedString(@"总榜")forState:UIControlStateNormal];
  111. [rightButton setTitleColor:kAppGrayColor1 forState:UIControlStateNormal];
  112. [rightButton setTitleColor:kAppGrayColor4 forState:UIControlStateSelected];
  113. [rightButton addTarget:self action:@selector(totalListClick:) forControlEvents:UIControlEventTouchUpInside];
  114. UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
  115. self.navigationItem.rightBarButtonItem = rightBarButtonItem;
  116. }
  117. [self.view addSubview:self.titleL];
  118. [self.view addSubview:self.backBtn];
  119. }
  120. - (void)viewWillAppear:(BOOL)animated {
  121. [super viewWillAppear:animated];
  122. self.navigationController.navigationBarHidden = YES;
  123. }
  124. #pragma mark --SegmentView代理方法
  125. - (void)segmentView:(SegmentView*)segmentView selectIndex:(NSInteger)index
  126. {
  127. [UIView animateWithDuration:0.2f animations:^{
  128. _cScrollView.contentOffset = CGPointMake(_cScrollView.frame.size.width*index, 0);
  129. }];
  130. self.segBgView.centerX = index ==0 ? kScreenW / 4 : kScreenW / 4 * 3;
  131. self.segBgView.centerY = _listSegmentView.centerY;
  132. }
  133. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scroll
  134. {
  135. CGPoint offset = _cScrollView.contentOffset;
  136. NSInteger page = (offset.x + _cScrollView.frame.size.width/2) / _cScrollView.frame.size.width;
  137. // self.listSegmentView.indicatorView.hidden = NO;
  138. [_listSegmentView setSelectIndex:page];
  139. }
  140. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  141. {
  142. CGFloat pageWidth = scrollView.frame.size.width;
  143. NSInteger tmpPage = scrollView.contentOffset.x / pageWidth;
  144. float tmpPage2 = scrollView.contentOffset.x / pageWidth;
  145. NSInteger page = tmpPage2-tmpPage>=0.5 ? tmpPage+1 : tmpPage;
  146. if (_startPage != page)
  147. {
  148. [_listSegmentView setSelectIndex:page];
  149. _startPage = page;
  150. }
  151. }
  152. - (void)goToHomeWithModel:(UserModel *)model
  153. {
  154. SHomePageVC *tmpController= [[SHomePageVC alloc]init];
  155. tmpController.user_id = model.user_id;
  156. tmpController.type = 0;
  157. [self.navigationController pushViewController:tmpController animated:NO];
  158. }
  159. - (void)backClick
  160. {
  161. if (self.navigationController.viewControllers.count >1)
  162. {
  163. [self.navigationController popViewControllerAnimated:YES];
  164. }else
  165. {
  166. [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  167. }
  168. }
  169. - (void)totalListClick:(UIButton *)button
  170. {
  171. LeaderboardViewController *boardVC = [[LeaderboardViewController alloc]init];
  172. boardVC.isHiddenTabbar = YES;
  173. if (self.liveHost_id.length)
  174. {
  175. boardVC.hostLiveId = self.liveHost_id;
  176. }
  177. [self.navigationController pushViewController:boardVC animated:YES];
  178. }
  179. -(UIImageView *)bgImgView{
  180. if (!_bgImgView) {
  181. _bgImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 420)];
  182. _bgImgView.image = [UIImage imageNamed:@"bogo_contributeList_BGImage"];
  183. BogoRankHeadGifView *headGifView = [[BogoRankHeadGifView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, _bgImgView.height)];
  184. headGifView.backgroundColor = kClearColor;
  185. [_bgImgView addSubview:headGifView];
  186. }
  187. return _bgImgView;
  188. }
  189. -(UIImageView *)segBgView{
  190. if (!_segBgView) {
  191. _segBgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kRealValue(66), kRealValue(23))];
  192. _segBgView.image = [UIImage imageNamed:@"bogo_contribute_seg_bgView"];
  193. _segBgView.userInteractionEnabled = YES;
  194. _segBgView.centerX =kScreenW / 4;
  195. _segBgView.centerY = _listSegmentView.centerY;
  196. }
  197. return _segBgView;
  198. }
  199. @end