SmallVideoViewController.m 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. //
  2. // SmallVideoViewController.m
  3. // BuguLive
  4. //
  5. // Created by 范东 on 2019/1/21.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "SmallVideoViewController.h"
  9. #import "MSmallVideoVC.h"
  10. #import "SSearchVC.h"
  11. #import "SegmentView.h"
  12. @interface SmallVideoViewController ()<UIScrollViewDelegate,SegmentViewDelegate>{
  13. UITableView *_listTableView;
  14. int _buttonCount; //button个数
  15. UIButton *_dayBoardBtn; //日榜
  16. UIButton *_monthBoardBtn; //月榜
  17. UIButton *_totalBoardbtn; //总榜
  18. UIButton *_meritBtn; //功德榜
  19. UIButton *_contriBtn; //贡献榜
  20. UIView *_topicView;
  21. UIView *_headView;
  22. NSArray *_listItems;
  23. UIScrollView *_tScrollView;
  24. CGRect _listSegmentFrame;
  25. MSmallVideoVC *_hotVC; //热门
  26. MSmallVideoVC *_latestVC; //最新
  27. MSmallVideoVC *_nearVC; //附近
  28. NSInteger _startPage; // 起始页
  29. }
  30. @property ( nonatomic, strong) JSBadgeView *badge;
  31. @end
  32. @implementation SmallVideoViewController
  33. - (void)viewWillAppear:(BOOL)animated
  34. {
  35. [super viewWillAppear:animated];
  36. [self.navigationController setNavigationBarHidden:NO animated:animated];
  37. // [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:animated];
  38. _headView.hidden = NO;
  39. [self loadBtnBadageData];
  40. }
  41. - (void)viewDidLoad
  42. {
  43. [super viewDidLoad];
  44. SUS_WINDOW.window_Tap_Ges.enabled = NO;
  45. SUS_WINDOW.window_Pan_Ges.enabled = NO;
  46. _startPage = 1;
  47. self.view.backgroundColor = kNavBarThemeColor;
  48. //分段视图
  49. _listItems =[NSArray arrayWithObjects:ASLocalizedString(@"热门"),ASLocalizedString(@"最新"),ASLocalizedString(@"附近"), nil];
  50. self.navigationItem.title = @"";
  51. [self createHeadView];
  52. [self leftOrRightNavItem];
  53. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(iMChatHaveNotification:) name:g_notif_chatmsg object:nil];
  54. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTableViewStatus) name:@"changeTableViewStatus" object:nil];
  55. }
  56. - (void)viewWillDisappear:(BOOL)animated
  57. {
  58. [super viewWillDisappear:animated];
  59. _headView.hidden = YES;
  60. }
  61. - (void)changeTableViewStatus{
  62. [_hotVC refreshHeader];
  63. [_latestVC refreshHeader];
  64. [_nearVC refreshHeader];
  65. }
  66. #pragma mark 导航栏部分
  67. //搜索
  68. - (void)searchClick
  69. {
  70. if (self.isHiddenTabbar)
  71. {
  72. [[AppDelegate sharedAppDelegate]popViewController];
  73. }else
  74. {
  75. SSearchVC *searchVC = [[SSearchVC alloc]init];
  76. searchVC.searchType = @"0";
  77. [[AppDelegate sharedAppDelegate] pushViewController:searchVC animated:YES];
  78. }
  79. }
  80. - (void)createHeadView
  81. {
  82. _headView = [[UIView alloc]initWithFrame:CGRectMake((kScreenW-200)/2.0, 0, 200, 44)];
  83. _headView.backgroundColor = kClearColor;
  84. [self.navigationController.navigationBar addSubview:_headView];
  85. _listSegmentFrame = CGRectMake(0, 0, 200, 44);
  86. _listSegmentView = [[SegmentView alloc]initWithFrame:_listSegmentFrame andItems:_listItems andSize:16 border:NO isrankingRist:NO];
  87. _listSegmentView.backgroundColor = kClearColor;
  88. _listSegmentView.delegate = self;
  89. [_listSegmentView setSelectIndex:0];
  90. [_headView addSubview:_listSegmentView];
  91. if (self.isHiddenTabbar)
  92. {
  93. _tScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-kNavigationBarHeight-kStatusBarHeight)];
  94. }else
  95. {
  96. _tScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-kNavigationBarHeight-kStatusBarHeight-kTabBarHeight)];
  97. }
  98. _tScrollView.backgroundColor = kClearColor;
  99. _tScrollView.contentSize = CGSizeMake(3*kScreenW, 0);
  100. _tScrollView.pagingEnabled = YES;
  101. _tScrollView.bounces = NO;
  102. _tScrollView.showsHorizontalScrollIndicator = NO;
  103. _tScrollView.delegate = self;
  104. [self.view addSubview:_tScrollView];
  105. _tScrollView.contentOffset = CGPointMake(0, 0);
  106. //热门
  107. if (!_hotVC)
  108. {
  109. _hotVC = [[MSmallVideoVC alloc]init];
  110. _hotVC.view.frame = CGRectMake(0, 0, kScreenW, _hotVC.view.height);
  111. _hotVC.paramDict = [NSDictionary dictionaryWithObject:@"1" forKey:@"order"];
  112. }
  113. [_tScrollView addSubview:_hotVC.view];
  114. //最新
  115. if (!_latestVC){
  116. _latestVC = [[MSmallVideoVC alloc]init];
  117. _latestVC.view.frame = CGRectMake(kScreenW, 0, kScreenW, _hotVC.view.height);
  118. _latestVC.paramDict = [NSDictionary dictionaryWithObject:@"2" forKey:@"order"];
  119. }
  120. [_tScrollView addSubview:_latestVC.view];
  121. //附近
  122. if (!_nearVC) {
  123. _nearVC = [[MSmallVideoVC alloc]init];
  124. _nearVC.view.frame = CGRectMake(kScreenW*2, 0, kScreenW, _hotVC.view.height);
  125. _nearVC.paramDict = [NSDictionary dictionaryWithObject:@"3" forKey:@"order"];
  126. }
  127. [_tScrollView addSubview:_nearVC.view];
  128. }
  129. - (void)leftOrRightNavItem
  130. {
  131. // 左上角按钮
  132. UIButton *leftButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 35, kNavigationBarHeight)];
  133. if (self.isHiddenTabbar)
  134. {
  135. [leftButton setImage:[UIImage imageNamed:@"com_arrow_vc_back"] forState:UIControlStateNormal];
  136. }
  137. else
  138. {
  139. [leftButton setImage:[UIImage imageNamed:@"hm_search"] forState:UIControlStateNormal];
  140. }
  141. [leftButton addTarget:self action:@selector(searchClick) forControlEvents:UIControlEventTouchUpInside];
  142. leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  143. UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
  144. self.navigationItem.leftBarButtonItem = leftBarButtonItem;
  145. // 右上角按钮
  146. UIButton *rightButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 35, kNavigationBarHeight)];
  147. [rightButton setImage:[UIImage imageNamed:@"hm_private_message"] forState:UIControlStateNormal];
  148. [rightButton addTarget:self action:@selector(clickedIMChat) forControlEvents:UIControlEventTouchUpInside];
  149. rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  150. UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
  151. self.navigationItem.rightBarButtonItem = rightButtonItem;
  152. // 设置角标
  153. [self initBadgeBtn:rightButton];
  154. [self loadBtnBadageData];
  155. }
  156. #pragma mark --SegmentView代理方法
  157. - (void)segmentView:(SegmentView*)segmentView selectIndex:(NSInteger)index
  158. {
  159. [UIView animateWithDuration:0.2f animations:^{
  160. _tScrollView.contentOffset = CGPointMake(_tScrollView.frame.size.width*index, 0);
  161. }];
  162. }
  163. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scroll
  164. {
  165. CGPoint offset = _tScrollView.contentOffset;
  166. NSInteger page = (offset.x + _tScrollView.frame.size.width/2) / _tScrollView.frame.size.width;
  167. // self.segmentView.indicatorView.hidden = NO;
  168. [_listSegmentView setSelectIndex:page];
  169. }
  170. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  171. {
  172. CGFloat pageWidth = scrollView.frame.size.width;
  173. NSInteger tmpPage = scrollView.contentOffset.x / pageWidth;
  174. float tmpPage2 = scrollView.contentOffset.x / pageWidth;
  175. NSInteger page = tmpPage2-tmpPage>=0.5 ? tmpPage+1 : tmpPage;
  176. if (_startPage != page)
  177. {
  178. [_listSegmentView setSelectIndex:page];
  179. _startPage = page;
  180. }
  181. }
  182. - (void)pushToHomePage:(UserModel *)model
  183. {
  184. SHomePageVC *homeVC = [[SHomePageVC alloc]init];
  185. homeVC.user_id = model.user_id;
  186. // homeVC.user_nickname =model.nick_name;
  187. homeVC.type = 0;
  188. [[AppDelegate sharedAppDelegate]pushViewController:homeVC animated:YES];
  189. }
  190. #pragma mark - ----------------------- 私信消息、角标 -----------------------
  191. #pragma mark IM
  192. - (void)clickedIMChat
  193. {
  194. BGConversationSegmentController *chatListVC = [[BGConversationSegmentController alloc]init];
  195. [[AppDelegate sharedAppDelegate] pushViewController:chatListVC animated:YES];
  196. }
  197. - (void)iMChatHaveNotification:(NSNotification*)notification
  198. {
  199. //all 角标数据
  200. [self loadBtnBadageData];
  201. }
  202. /**
  203. 设置 角标
  204. @param sender 对应的控件
  205. */
  206. - (void)initBadgeBtn:(UIButton *)sender
  207. {
  208. //-好友
  209. _badge = [[JSBadgeView alloc]initWithParentView:sender alignment:JSBadgeViewAlignmentTopRight];
  210. _badge.badgePositionAdjustment = CGPointMake(0, 12);
  211. }
  212. /**
  213. 获取角标的数据: 注意:调All未读/调好友&&非好友方法 算All时,别调后者2各和来算,里面有耗时操作
  214. 使用:1.在willApperar 2.SDK监听会发通知,通知的方法/block 里调用
  215. 给控件初始化一个角标
  216. badage的 数据 获取(个人页面获取所有未读的条数)
  217. 1.在willApear里调用一次 2.SDk消息变化,接受通知,在通知方法还要调用 用于更新 角标数据
  218. */
  219. - (void)loadBtnBadageData
  220. {
  221. [SFriendObj getAllUnReadCountComplete:^(int num) {
  222. //all
  223. int scount = num;
  224. if( scount )
  225. {
  226. if(scount > 98)
  227. {
  228. _badge.badgeText = @"99+";
  229. }
  230. else
  231. {
  232. _badge.badgeText = [NSString stringWithFormat:@"%d",scount];
  233. }
  234. }
  235. else
  236. {
  237. _badge.badgeText = nil;
  238. }
  239. }];
  240. }
  241. @end