YHTimeLineViewController.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. //
  2. // YHTimeLineViewController.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2019/8/23.
  6. // Copyright © 2019年 xfg. All rights reserved.
  7. //
  8. #import "YHTimeLineViewController.h"
  9. #import "YHTimeLineListController.h"
  10. #import "ReleaseTopicVC.h"//话题搜索
  11. #import "MGNewDTNavView.h"
  12. //#import "MGNewDTHeadView.h"
  13. #import "BogoDTHeadView.h"
  14. #import "BzoneLogic.h"
  15. #import "TCUtil.h"
  16. #import "BGTopicTimeLineListController.h"
  17. #import "BGSystemMsgVC.h"
  18. //附近的人
  19. #import "MGNewDTNearByViewController.h"
  20. #import "BogoTimeLineListViewController.h"
  21. #define YHTimeLineMagrin 20 //
  22. @interface YHTimeLineViewController ()<UIScrollViewDelegate,MGTimeLineDidScrollViewDelegate,BogoTimeLineDidScrollViewDelegate>
  23. @property (nonatomic, strong) MLMSegmentHead *segHead;
  24. @property (nonatomic, strong) MLMSegmentScroll *segScroll;
  25. //@property(nonatomic, strong) YHTimeLineListController *firstVC;
  26. //@property(nonatomic, strong) YHTimeLineListController *mineVC;
  27. //@property(nonatomic, strong) YHTimeLineListController *recommandVC;
  28. //@property(nonatomic, strong) YHTimeLineListController *nearVC;
  29. @property(nonatomic, strong) BogoTimeLineListViewController *firstVC;
  30. @property(nonatomic, strong) BogoTimeLineListViewController *mineVC;
  31. @property(nonatomic, strong) BogoTimeLineListViewController *recommandVC;
  32. @property(nonatomic, strong) BogoTimeLineListViewController *nearVC;
  33. //view
  34. @property(nonatomic, strong) MGNewDTNavView *navView;
  35. @property(nonatomic, strong) BogoDTHeadView *headView;
  36. @property(nonatomic, strong) UIScrollView *scrollView;
  37. @property(nonatomic, strong) NSArray *list;
  38. @property(nonatomic, strong) QMUIButton *postBtn;
  39. @property(nonatomic, strong) BzoneLogic *logic;
  40. @property(nonatomic, strong) UIView *lineView;
  41. @end
  42. @implementation YHTimeLineViewController
  43. - (void)viewDidLoad {
  44. [super viewDidLoad];
  45. // Do any additional setup after loading the view.
  46. [self setUpView];
  47. [self segmentStyle1];
  48. [self requsetModel];
  49. }
  50. -(void)setUpView{
  51. self.navView.hidden = YES;
  52. [self.view addSubview:self.navView];
  53. [self.view addSubview:self.scrollView];
  54. [self.scrollView addSubview:self.headView];
  55. // self.scrollView.frame = CGRectMake(0, self.navView.bottom, kScreenW, kScreenH - kTabBarHeight - self.navView.bottom);
  56. self.scrollView.frame = CGRectMake(0, 0, kScreenW, kScreenH - kTabBarHeight - kTopHeight);
  57. self.navigationController.navigationBarHidden = YES;
  58. }
  59. - (void)viewWillAppear:(BOOL)animated {
  60. [super viewWillAppear:animated];
  61. self.navigationController.navigationBarHidden = YES;
  62. // [self requsetModel];
  63. [self requsetUnRead_Msg];
  64. }
  65. -(void)requsetModel{
  66. self.logic = [BzoneLogic new];
  67. if (kIsCheckingVersion())
  68. {
  69. return;
  70. }
  71. [self.logic dynamicGetTopicModelWithUID:[BGIMLoginManager sharedInstance].loginParam.identifier Success:^(NSDictionary * _Nonnull dic) {
  72. if ([[dic valueForKey:@"status"] integerValue] == 1) {
  73. for (NSDictionary *subDic in [dic valueForKey:@"data"]) {
  74. MGDynamicTopicModel *model = [MGDynamicTopicModel itemWithDic:subDic];
  75. [self.logic.topicArr addObject:model];
  76. }
  77. [self.headView resetTopicModel:self.logic.topicArr];
  78. }
  79. }];
  80. }
  81. -(void)requsetUnRead_Msg{
  82. self.logic = [BzoneLogic new];
  83. [self.logic fetchUnRead_MsgSuccess:^(NSDictionary * _Nonnull dic) {
  84. if ([[dic valueForKey:@"status"] integerValue] == 1) {
  85. if ([dic[@"no_read_msg"] intValue] ==0) {
  86. self.navView.jsbadge.badgeText = nil;
  87. }else{
  88. self.navView.jsbadge.badgeText = [NSString stringWithFormat:@"%@",dic[@"no_read_msg"]];
  89. }
  90. [ self.navView.jsbadge setNeedsLayout];
  91. }
  92. }];
  93. }
  94. - (void)segmentStyle1 {
  95. self.firstVC = [[BogoTimeLineListViewController alloc]initWithIndexAct:MGDTHOMETYPE_RECOMMAND withUID:@"" isHomePageFrame:CGRectMake(0, 0, kScreenW, kScreenH - kTopHeight - kTabBarHeight - MG_BOTTOM_MARGIN)];
  96. // alloc]initWithIndexAct:MGDTHOMETYPE_RECOMMAND withUID:@""];
  97. _list = @[ ASLocalizedString(@"推荐"),ASLocalizedString(@"关注"),/*ASLocalizedString(@"附近"),*/ASLocalizedString(@"我的")];
  98. _segHead = [[MLMSegmentHead alloc] initWithFrame:CGRectMake(15, self.headView.bottom, SCREEN_WIDTH - 60 , 40) titles:_list headStyle:SegmentHeadStyleLine layoutStyle:MLMSegmentLayoutLeft];
  99. // _segHead.centerX = kScreenW / 2;
  100. _segHead.backgroundColor = UIColor.clearColor;
  101. _segHead.headColor = UIColor.clearColor;
  102. //tab颜色
  103. _segHead.selectColor = [UIColor colorWithHexString:@"#333333"];
  104. _segHead.deSelectColor = [UIColor colorWithHexString:@"#666666"];
  105. _segHead.selectFont = [UIFont boldSystemFontOfSize:18];
  106. _segHead.deSelectFont = [UIFont systemFontOfSize:15];
  107. _segHead.titlesScroll.backgroundColor = UIColor.clearColor;
  108. _segHead.lineScale = 0.3;
  109. _segHead.lineHeight = 3.5;
  110. _segHead.lineColor = [UIColor colorWithHexString:@"#78FFCB"];
  111. _segHead.bottomLineHeight = 0;
  112. UIView * line = [self.segHead getScrollLineView];
  113. CGRect rect = line.frame;
  114. rect.origin.y -= 7;
  115. line.frame = rect;
  116. // _segHead.deSelectColor = [UIColor colorWithRed:0.91 green:0.47 blue:0.62 alpha:1.00];
  117. self.view.backgroundColor = kClearColor;
  118. // CF6;
  119. _segScroll = [[MLMSegmentScroll alloc] initWithFrame:CGRectMake(0, _segHead.bottom, SCREEN_WIDTH, SCREEN_HEIGHT-self.headView.height-self.navView.height - kTabBarHeight) vcOrViews:[self vcArr:_list.count]];
  120. _segScroll.loadAll = NO;
  121. _segScroll.showIndex = 0;
  122. _segScroll.backgroundColor = UIColor.clearColor;
  123. [MLMSegmentManager associateHead:_segHead withScroll:_segScroll completion:^{
  124. [self.scrollView addSubview:_segHead];
  125. self.lineView.top = _segHead.bottom + 8;
  126. [self.scrollView addSubview:self.lineView];
  127. [self.scrollView addSubview:_segScroll];
  128. // [self setHeadBottomLineView];
  129. }];
  130. }
  131. //-(void)setHeadBottomLineView{
  132. // UIView *line = [_segHead getScrollLineView];
  133. //
  134. // line.layer.cornerRadius = 2;
  135. // line.layer.masksToBounds = YES;
  136. //
  137. // CAGradientLayer *gl = [CAGradientLayer layer];
  138. // gl.frame = line.bounds;
  139. // gl.startPoint = CGPointMake(0, 0.5);
  140. // gl.endPoint = CGPointMake(1, 0.5);
  141. // gl.colors = @[(__bridge id)[UIColor colorWithHexString:@"#9E64FF"].CGColor, (__bridge id)[UIColor colorWithHexString:@"#EF60F6"].CGColor];
  142. // gl.locations = @[@(0), @(1.0f)];
  143. // [line.layer insertSublayer:gl atIndex:0];
  144. //}
  145. -(void)handleSearchEvent{
  146. // [self.firstVC handleSearchEvent];
  147. //// [self.mineVC handleSearchEvent];
  148. //// [self.nearVC handleSearchEvent];
  149. }
  150. -(void)reloadDynamicData{
  151. // [self.firstVC reloadDynamicData];
  152. // [self.mineVC reloadDynamicData];
  153. // [self.nearVC reloadDynamicData];
  154. }
  155. -(void)protocolTimeLineDidScrollView:(UIScrollView *)scrollView offset:(CGFloat)offset{
  156. NSLog(@"offset%f",offset);
  157. NSLog(@"offset%f",offset);
  158. NSLog(@"%@",scrollView);
  159. NSLog(@"View.contentSize.height:%f",scrollView.contentSize.height);
  160. NSLog(@"%f",kScreenH - self.headView.height - kTabBarHeight - MG_TOP_MARGIN - MG_BOTTOM_MARGIN)
  161. if (scrollView.contentSize.height < kScreenH - kTopHeight - kTabBarHeight) {
  162. [self.scrollView setContentOffset:CGPointMake(0, offset < 0 ? 0 : offset)];
  163. self.segScroll.height = scrollView.height = kScreenH - kTopHeight - kTabBarHeight - YHTimeLineMagrin;
  164. return;
  165. }
  166. if (offset > self.headView.height) {
  167. [self.scrollView setContentOffset:CGPointMake(0, self.headView.height)];
  168. self.segScroll.height = scrollView.height = kScreenH - kTopHeight - 49 - MG_BOTTOM_MARGIN;// - self.headView.height
  169. // kScreenH - self.navView.height - kTabBarHeight - self.headView.height;
  170. //
  171. NSLog(@"%f",kStatusBarHeight);
  172. NSLog(@"%f",kTopHeight);
  173. NSLog(@"%f",MG_BOTTOM_SAFE_HEIGHT);
  174. NSLog(@"%f",self.headView.height);
  175. // self.segScroll.height = scrollView.height = kScreenH - self.navView.height - kTabBarHeight - self.headView.height;
  176. return;
  177. }
  178. if (scrollView.height < kScreenH - self.navView.height - self.segHead.height - kTabBarHeight && offset > 0) {
  179. return;
  180. }
  181. self.segScroll.height = scrollView.height = kScreenH - self.navView.height - self.segHead.height - kTabBarHeight - YHTimeLineMagrin;
  182. [self.scrollView setContentOffset:CGPointMake(0, offset < 0 ? 0 : offset)];
  183. }
  184. #pragma mark - 数据源
  185. - (NSArray *)vcArr:(NSInteger)count
  186. {
  187. NSMutableArray *arr = [NSMutableArray array];
  188. CGRect frame = CGRectMake(0, 0, kScreenW, kScreenH - kTopHeight - kTabBarHeight - MG_BOTTOM_MARGIN);
  189. BogoTimeLineListViewController *vc2 = [[BogoTimeLineListViewController alloc]initWithIndexAct:MGDTHOMETYPE_CONCERT withUID:@"" isHomePageFrame:frame];
  190. BogoTimeLineListViewController *vc3 = [[BogoTimeLineListViewController alloc]initWithIndexAct:MGDTHOMETYPE_NEARBY withUID:@"" isHomePageFrame:frame];
  191. // YHTimeLineListController *vc4 = [[YHTimeLineListController alloc]initWithIndexAct:MGDTHOMETYPE_VIDEO withUID:@""];
  192. BogoTimeLineListViewController *vc5 = [[BogoTimeLineListViewController alloc]initWithIndexAct:MGDTHOMETYPE_MY withUID:[BGIMLoginManager sharedInstance].loginParam.identifier isHomePageFrame:frame];;
  193. self.firstVC.timeLineDelegate = self;
  194. vc2.timeLineDelegate = self;
  195. vc3.timeLineDelegate = self;
  196. // vc4.timeLineDelegate = self;
  197. vc5.timeLineDelegate = self;
  198. [arr addObject:self.firstVC];
  199. [arr addObject:vc2];
  200. // [arr addObject:vc3];
  201. // [arr addObject:vc4];
  202. [arr addObject:vc5];
  203. return arr;
  204. }
  205. -(UIScrollView *)scrollView{
  206. if (!_scrollView) {
  207. _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  208. _scrollView.delegate = self;
  209. _scrollView.backgroundColor = UIColor.clearColor;
  210. }
  211. return _scrollView;
  212. }
  213. //放在当前view上
  214. -(MGNewDTNavView *)navView{
  215. if (!_navView) {
  216. _navView = [[MGNewDTNavView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kTopHeight)];
  217. __weak __typeof(self)weakSelf = self;
  218. _navView.clickPostBlock = ^(NSInteger i) {
  219. if (i == 0) {
  220. ReleaseTopicVC *pushVC = [ReleaseTopicVC new];
  221. pushVC.releaseTopicBlock = ^(MGDynamicTopicModel * _Nonnull topic) {
  222. BGTopicTimeLineListController *pushVC = [BGTopicTimeLineListController new];
  223. pushVC.topic = topic;
  224. [[AppDelegate sharedAppDelegate]pushViewController:pushVC animated:YES];
  225. };
  226. [[AppDelegate sharedAppDelegate]pushViewController:pushVC animated:YES];
  227. // presentViewController:pushVC animated:YES completion:nil];
  228. }else if (i == 1){
  229. [weakSelf handleSearchEvent];
  230. }else if (i == 2){
  231. BGSystemMsgVC *pushVC = [BGSystemMsgVC new];
  232. [[AppDelegate sharedAppDelegate]pushViewController:pushVC animated:YES];
  233. }
  234. };
  235. }
  236. return _navView;
  237. }
  238. //放在scrollview上的
  239. -(BogoDTHeadView *)headView{
  240. if (!_headView) {
  241. _headView = [[NSBundle mainBundle]loadNibNamed:@"BogoDTHeadView" owner:self options:nil].firstObject;
  242. _headView.backgroundColor = kClearColor;
  243. if (isIPhone6()) {
  244. _headView.frame = CGRectMake(0, 0, kScreenW, kRealValue(116 + 15 + 15 ));
  245. }else{
  246. _headView.frame = CGRectMake(0, 0, kScreenW, kRealValue(116 + 15 + 15 + 20));
  247. }
  248. // _headView = [[MGNewDTHeadView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kRealValue(130))];
  249. // FWWeakify(self)
  250. // _headView.MGNewDTHeadViewTopicBlock = ^(NSInteger index) {
  251. // FWStrongify(self)
  252. //
  253. // if (index == 1000) {//全部话题
  254. // MGNewDTNearByViewController *pushVC = [[MGNewDTNearByViewController alloc]initWithType:MGNEWDTTYPE_TOPIC];
  255. // [[AppDelegate sharedAppDelegate]pushViewController:pushVC animated:YES];
  256. // }else{
  257. // BGTopicTimeLineListController *pushVC = [BGTopicTimeLineListController new];
  258. //// if (self.logic.topicArr.count > index - 1) {
  259. // pushVC.topic = _headView.topicArr[index];
  260. //// self.logic.topicArr[index];
  261. // [[AppDelegate sharedAppDelegate]pushViewController:pushVC animated:YES];
  262. //// }
  263. // }
  264. // };
  265. }
  266. return _headView;
  267. }
  268. -(UIView *)lineView{
  269. if (!_lineView) {
  270. _lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 3)];
  271. _lineView.backgroundColor = kClearColor;
  272. }
  273. return _lineView;
  274. }
  275. @end