YBCenterVC.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. //
  2. // YBCenterVC.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2022/5/30.
  6. // Copyright © 2022 cat. All rights reserved.
  7. //
  8. #import "YBCenterVC.h"
  9. #import "YBCenterTopView.h"
  10. #import <TYTabPagerBar.h>
  11. #import <TYPagerController.h>
  12. #import "MessageListModel.h"
  13. #import "CenterListVC.h"
  14. @interface YBCenterVC ()<UIScrollViewDelegate,TYTabPagerBarDelegate,TYTabPagerBarDataSource,TYPagerControllerDelegate,TYPagerControllerDataSource,ListScrollDelegate>
  15. {
  16. CGFloat scrContentH;
  17. CGFloat segStartY;
  18. }
  19. @property(nonatomic,strong)YBCenterTopView *topView;
  20. @property(nonatomic,strong)TYTabPagerBar *tabBar;
  21. @property(nonatomic,strong)TYPagerController *pagerController;
  22. @property(nonatomic,strong)NSArray *dataArray;
  23. @property(nonatomic,assign)BOOL followed;
  24. @property(nonatomic,strong)UIScrollView *scrollview;
  25. @property(nonatomic,strong)CenterListVC *listVC1;
  26. @property(nonatomic,strong)CenterListVC *listVC2;
  27. @property(nonatomic,strong)CenterListVC *listVC3;
  28. @end
  29. @implementation YBCenterVC
  30. - (void)viewWillAppear:(BOOL)animated{
  31. [super viewWillAppear:animated];
  32. [self pullData];
  33. }
  34. - (void)viewWillDisappear:(BOOL)animated{
  35. [super viewWillDisappear:animated];
  36. [_topView removeLivingAnimation];
  37. }
  38. - (void)viewDidAppear:(BOOL)animated{
  39. [super viewDidAppear:animated];
  40. }
  41. - (UIStatusBarStyle)preferredStatusBarStyle {
  42. if (@available(iOS 13.0,*)) {
  43. return UIStatusBarStyleDarkContent;
  44. }
  45. return UIStatusBarStyleDefault;
  46. }
  47. - (void)viewDidLoad {
  48. [super viewDidLoad];
  49. self.subNavi.backgroundColor = UIColor.whiteColor;
  50. self.titleL.textColor = UIColor.blackColor;
  51. _otherUid ? _otherUid:(_otherUid=[Config getOwnID]);
  52. scrContentH = 0;
  53. _followed = NO;
  54. [self.view addSubview:self.scrollview];
  55. self.view.backgroundColor = UIColor.whiteColor;
  56. _scrollview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  57. [self.rightBtn setImage:[UIImage imageNamed:@"center_more"] forState:0];
  58. if (![_otherUid isEqual:[Config getOwnID]]) {
  59. //他人
  60. self.leftBtn.hidden = NO;
  61. self.rightBtn.hidden = NO;
  62. }else{
  63. //自己
  64. self.leftBtn.hidden = YES;
  65. self.rightBtn.hidden = YES;
  66. }
  67. //从其他页面push过来
  68. if (_isPush) {
  69. self.leftBtn.hidden = NO;
  70. }
  71. // 0 - 系统管理员
  72. if ([_otherUid isEqual:@"0"]) {
  73. self.rightBtn.hidden = YES;
  74. }
  75. //动态改变
  76. self.subNavi.alpha = 0;
  77. self.rightBtn.hidden = YES;
  78. [_tabBar reloadData];
  79. [_pagerController reloadData];
  80. }
  81. -(void)pullData {
  82. // if([_otherUid isEqual:@"-9999"]){
  83. // _otherUid = [Config getOwnID];
  84. // }
  85. NSString *url = [NSString stringWithFormat:@"User.getUserHome&uid=%@&touid=%@",[Config getOwnID],_otherUid];
  86. [YBNetworking postWithUrl:url Dic:nil Suc:^(int code, id info, NSString *msg) {
  87. if (code == 0) {
  88. NSDictionary *infoDic = [info firstObject];
  89. if ([_otherUid isEqual:[Config getOwnID]]) {
  90. //自己个人中心
  91. [Config saveOwnNicename:minstr([infoDic valueForKey:@"user_nickname"])];
  92. [Config saveUserSex:minstr([infoDic valueForKey:@"sex"])];
  93. [Config saveUserAvatar:minstr([infoDic valueForKey:@"avatar"])];
  94. [Config saveUserCity:minstr([infoDic valueForKey:@"city"])];
  95. [Config saveUserHomeTown:minstr([infoDic valueForKey:@"hometown"])];
  96. }
  97. self.titleL.text = minstr([infoDic valueForKey:@"user_nickname"]);
  98. _topView.dataDic = infoDic;
  99. [self updateTop:infoDic];
  100. }else if (code == 700){
  101. [PublicObj tokenExpired:msg];
  102. }else{
  103. [MBProgressHUD showPop:msg];
  104. }
  105. } Fail:^(id fail) {
  106. }];
  107. }
  108. -(void)updateTop:(NSDictionary *)infoDic {
  109. NSString *itemNums1 = [NSString stringWithFormat:@"%@ %@",YZMsg(@"作品"),[infoDic valueForKey:@"workVideos"]];
  110. NSString *itemNums2 = [NSString stringWithFormat:@"%@ %@",YZMsg(@"喜欢"),[infoDic valueForKey:@"likeVideos"]];
  111. NSString *itemNums3 = [NSString stringWithFormat:@"%@ %@",YZMsg(@"收藏"),[infoDic valueForKey:@"collectionVideos"]];
  112. if ([_otherUid isEqual:[Config getOwnID]]) {
  113. _dataArray = @[itemNums1,itemNums2,itemNums3];
  114. }else{
  115. _dataArray = @[itemNums1,itemNums2];
  116. }
  117. [_tabBar reloadData];
  118. }
  119. -(void)topViewEvent:(TopCtrType)ctrType andRes:(NSDictionary *)resDic {
  120. if (ctrType == TopCtrType_Layout) {
  121. CGFloat top_height = [minstr([resDic valueForKey:@"top_height"]) floatValue];
  122. _topView.height = top_height;
  123. segStartY = _topView.height;
  124. if (!_isTabbar) {
  125. scrContentH = _window_height + segStartY-64-statusbarHeight;
  126. }else{
  127. scrContentH = _window_height + segStartY-49-64-statusbarHeight-ShowDiff;
  128. }
  129. _scrollview.contentSize = CGSizeMake(0, scrContentH);
  130. _tabBar.frame = CGRectMake(0, _topView.bottom, _window_width, 44);
  131. _pagerController.view.frame = CGRectMake(0, _tabBar.bottom, _window_width, scrContentH-segStartY-_tabBar.height);
  132. }else if (ctrType == TopCtrType_Attent){
  133. NSString *isattent = minstr([resDic valueForKey:@"isattent"]);
  134. if (self.followEvent) {
  135. self.followEvent(isattent);
  136. }
  137. }
  138. }
  139. #pragma mark - set/get
  140. -(UIScrollView *)scrollview {
  141. if (!_scrollview) {
  142. CGFloat scrH = _window_height-49-ShowDiff;
  143. if (!_isTabbar) {
  144. scrH = _window_height;
  145. }
  146. _scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0,_window_width, scrH)];
  147. _scrollview.backgroundColor = UIColor.whiteColor;
  148. _scrollview.delegate = self;
  149. _scrollview.bounces = NO;
  150. _scrollview.pagingEnabled = NO;
  151. _scrollview.showsVerticalScrollIndicator = NO;
  152. YBWeakSelf;
  153. _topView = [[YBCenterTopView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 0)];
  154. _topView.isChatPage = _isChatPage;
  155. _topView.isTabbar = _isTabbar;
  156. _topView.otherUid = _otherUid ? _otherUid : [Config getOwnID];;
  157. _topView.topEvent = ^(TopCtrType ctrType, NSDictionary *resDic) {
  158. [weakSelf topViewEvent:ctrType andRes:resDic];
  159. };
  160. [_scrollview addSubview:_topView];
  161. _dataArray = @[YZMsg(@"作品"),YZMsg(@"喜欢"),YZMsg(@"收藏")];
  162. CGFloat cellSpace = 40;
  163. if (![_otherUid isEqual:[Config getOwnID]]) {
  164. _dataArray = @[YZMsg(@"作品"),YZMsg(@"喜欢")];
  165. cellSpace = 80;
  166. }
  167. TYTabPagerBar *tabBar = [[TYTabPagerBar alloc]init];
  168. tabBar.dataSource = self;
  169. tabBar.delegate = self;
  170. tabBar.layout.barStyle = TYPagerBarStyleProgressView;
  171. tabBar.layout.selectedTextColor = UIColor.blackColor;
  172. tabBar.layout.normalTextColor = UIColor.grayColor;
  173. tabBar.layout.selectedTextFont = [UIFont boldSystemFontOfSize:17];
  174. tabBar.layout.normalTextFont = [UIFont systemFontOfSize:17];
  175. tabBar.layout.progressColor = UIColor.blackColor;
  176. tabBar.layout.progressHeight = 4;
  177. tabBar.layout.progressRadius = 2;
  178. tabBar.layout.progressHorEdging = 10;
  179. tabBar.layout.progressVerEdging = 5;
  180. tabBar.layout.cellWidth = 0;
  181. tabBar.layout.cellSpacing = cellSpace;
  182. tabBar.layout.adjustContentCellsCenter = YES;
  183. tabBar.backgroundColor = UIColor.clearColor;
  184. [tabBar registerClass:[TYTabPagerBarCell class] forCellWithReuseIdentifier:[TYTabPagerBarCell cellIdentifier]];
  185. [_scrollview addSubview:tabBar];
  186. _tabBar = tabBar;
  187. TYPagerController *pagerController = [[TYPagerController alloc] init];
  188. pagerController.dataSource = self;
  189. pagerController.delegate = self;
  190. pagerController.layout.adjustScrollViewInset = NO;
  191. pagerController.layout.scrollView.backgroundColor = UIColor.whiteColor;
  192. [self addChildViewController:pagerController];
  193. [_scrollview addSubview:pagerController.view];
  194. _pagerController = pagerController;
  195. }
  196. return _scrollview;
  197. }
  198. #pragma mark - TYTabPagerBarDataSource
  199. - (NSInteger)numberOfItemsInPagerTabBar {
  200. return _dataArray.count;
  201. }
  202. - (UICollectionViewCell<TYTabPagerBarCellProtocol> *)pagerTabBar:(TYTabPagerBar *)pagerTabBar cellForItemAtIndex:(NSInteger)index {
  203. UICollectionViewCell<TYTabPagerBarCellProtocol> *cell = [pagerTabBar dequeueReusableCellWithReuseIdentifier:[TYTabPagerBarCell cellIdentifier] forIndex:index];
  204. cell.titleLabel.text = _dataArray[index];
  205. return cell;
  206. }
  207. #pragma mark - TYTabPagerBarDelegate
  208. - (CGFloat)pagerTabBar:(TYTabPagerBar *)pagerTabBar widthForItemAtIndex:(NSInteger)index {
  209. NSString *title = _dataArray[index];
  210. return [pagerTabBar cellWidthForTitle:title];
  211. }
  212. - (void)pagerTabBar:(TYTabPagerBar *)pagerTabBar didSelectItemAtIndex:(NSInteger)index {
  213. [_pagerController scrollToControllerAtIndex:index animate:YES];
  214. }
  215. #pragma mark - TYPagerControllerDataSource
  216. - (NSInteger)numberOfControllersInPagerController {
  217. return _dataArray.count;
  218. }
  219. - (UIViewController *)pagerController:(TYPagerController *)pagerController controllerForIndex:(NSInteger)index prefetching:(BOOL)prefetching {
  220. if (index == 0) {
  221. // 作品
  222. if (!_listVC1) {
  223. _listVC1 = [self createListVCType:ListType_Normal];
  224. }
  225. return _listVC1;
  226. }else if (index == 1){
  227. // 喜欢
  228. if (!_listVC2) {
  229. _listVC2 = [self createListVCType:ListType_Likes];
  230. }
  231. return _listVC2;
  232. }else{
  233. // 收藏
  234. if (!_listVC3) {
  235. _listVC3 = [self createListVCType:ListType_Collection];
  236. }
  237. return _listVC3;
  238. }
  239. }
  240. -(CenterListVC *)createListVCType:(ListType)listType {
  241. CenterListVC *listVC = [[CenterListVC alloc]init];
  242. listVC.delegate = self;
  243. listVC.listType = listType;
  244. listVC.otherUid = _otherUid ? _otherUid : [Config getOwnID];
  245. listVC.isTabbar = _isTabbar;
  246. return listVC;
  247. }
  248. #pragma mark - TYPagerControllerDelegate
  249. - (void)pagerController:(TYPagerController *)pagerController transitionFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex animated:(BOOL)animated {
  250. [_tabBar scrollToItemFromIndex:fromIndex toIndex:toIndex animate:animated];
  251. }
  252. -(void)pagerController:(TYPagerController *)pagerController transitionFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex progress:(CGFloat)progress {
  253. [_tabBar scrollToItemFromIndex:fromIndex toIndex:toIndex progress:progress];
  254. }
  255. - (void)pagerController:(TYPagerController *)pagerController viewDidAppear:(UIViewController *)viewController forIndex:(NSInteger)index;{
  256. // 使用空数据代理会引起滑动问题,这里主动调用一下didScroll重置子视图的滚动属性
  257. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  258. [self scrollViewDidScroll:_scrollview];
  259. });
  260. }
  261. #pragma mark - 设置滑动事件
  262. - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
  263. //NSLog(@"centerVC======%f",velocity.y);
  264. }
  265. -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
  266. NSLog(@"centerVC==scrContentH:%f===did-scr===%f",segStartY-64-statusbarHeight,scrollView.contentOffset.y);
  267. if(scrollView.contentOffset.y >= segStartY-64-statusbarHeight){
  268. _listVC1.collectionView.scrollEnabled = YES;
  269. _listVC2.collectionView.scrollEnabled = YES;
  270. _listVC3.collectionView.scrollEnabled = YES;
  271. [self.view bringSubviewToFront:self.naviView];
  272. }else{
  273. _listVC1.collectionView.scrollEnabled = NO;
  274. _listVC2.collectionView.scrollEnabled = NO;
  275. _listVC3.collectionView.scrollEnabled = NO;
  276. [self.view sendSubviewToBack:self.naviView];
  277. }
  278. self.titleL.alpha = scrollView.contentOffset.y/(segStartY-64-statusbarHeight);
  279. self.subNavi.alpha = scrollView.contentOffset.y/(segStartY-64-statusbarHeight);
  280. }
  281. -(void)listScrollToTop:(CGFloat)Y{
  282. if (Y <0) {
  283. [_scrollview setContentOffset:CGPointMake(0,0) animated:YES];
  284. }
  285. }
  286. @end