GKDBViewController.m 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. //
  2. // GKDBViewController.m
  3. // GKPageScrollViewObjc
  4. //
  5. // Created by gaokun on 2020/12/17.
  6. // Copyright © 2020 gaokun. All rights reserved.
  7. //
  8. #import "GKDBViewController.h"
  9. #import "GKPageSmoothView.h"
  10. #import "GKDBListView.h"
  11. //新的滑动页面
  12. #import <GKPageSmoothView/GKPageSmoothView.h>
  13. #import <JXCategoryViewExt/JXCategoryView.h>
  14. @interface GKDBViewController ()<GKPageSmoothViewDataSource, GKPageSmoothViewDelegate, JXCategoryViewDelegate>
  15. @property (nonatomic, strong) UIView *titleView;
  16. @property (nonatomic, strong) GKPageSmoothView *smoothView;
  17. @property (nonatomic, strong) UIImageView *headerView;
  18. @property (nonatomic, strong) UIView *segmentedView;
  19. @property (nonatomic, strong) JXCategorySubTitleView *categoryView;
  20. @property (nonatomic, strong) JXCategoryIndicatorAlignmentLineView *lineView;
  21. @property (nonatomic, assign) BOOL isTitleViewShow;
  22. @property (nonatomic, assign) CGFloat originAlpha;
  23. @property (nonatomic, assign) CGFloat lastRatio;
  24. @end
  25. @implementation GKDBViewController
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. [self.view addSubview:self.smoothView];
  29. [self.smoothView mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.edges.equalTo(self.view);
  31. }];
  32. self.categoryView.contentScrollView = self.smoothView.listCollectionView;
  33. [self.smoothView reloadData];
  34. }
  35. #pragma mark - GKPageSmoothViewDataSource
  36. - (UIView *)headerViewInSmoothView:(GKPageSmoothView *)smoothView {
  37. return self.headerView;
  38. }
  39. - (UIView *)segmentedViewInSmoothView:(GKPageSmoothView *)smoothView {
  40. return self.segmentedView;
  41. }
  42. - (NSInteger)numberOfListsInSmoothView:(GKPageSmoothView *)smoothView {
  43. return self.categoryView.titles.count;
  44. }
  45. - (id<GKPageSmoothListViewDelegate>)smoothView:(GKPageSmoothView *)smoothView initListAtIndex:(NSInteger)index {
  46. GKDBListView *listView = [GKDBListView new];
  47. return listView;
  48. // GKBaseListViewController *listVC = [[GKBaseListViewController alloc] initWithListType:index];
  49. // listVC.shouldLoadData = YES;
  50. // return listVC;
  51. }
  52. #pragma mark - GKPageSmoothViewDelegate
  53. - (void)smoothView:(GKPageSmoothView *)smoothView listScrollViewDidScroll:(UIScrollView *)scrollView contentOffset:(CGPoint)contentOffset {
  54. if (smoothView.isOnTop) return;
  55. // 导航栏显隐
  56. CGFloat offsetY = contentOffset.y;
  57. CGFloat alpha = 0;
  58. if (offsetY <= 0) {
  59. alpha = 0;
  60. }else if (offsetY > 60) {
  61. alpha = 1;
  62. [self changeTitle:YES];
  63. }else {
  64. alpha = offsetY / 60;
  65. [self changeTitle:NO];
  66. }
  67. }
  68. - (void)smoothViewDragBegan:(GKPageSmoothView *)smoothView {
  69. if (smoothView.isOnTop) return;
  70. }
  71. - (void)smoothViewDragEnded:(GKPageSmoothView *)smoothView isOnTop:(BOOL)isOnTop {
  72. // titleView已经显示,不作处理
  73. if (self.isTitleViewShow) return;
  74. }
  75. - (void)changeTitle:(BOOL)isShow {
  76. }
  77. #pragma mark - JXCategoryViewDelegate
  78. - (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
  79. [self.smoothView showingOnTop];
  80. }
  81. #pragma mark - 懒加载
  82. - (UIView *)titleView {
  83. if (!_titleView) {
  84. _titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 100, 44.0f)];
  85. UIImage *image = [UIImage imageNamed:@"db_title"];
  86. UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
  87. imgView.frame = CGRectMake(0, 0, 44.0f * image.size.width / image.size.height, 44.0f);
  88. [_titleView addSubview:imgView];
  89. }
  90. return _titleView;
  91. }
  92. - (GKPageSmoothView *)smoothView {
  93. if (!_smoothView) {
  94. _smoothView = [[GKPageSmoothView alloc] initWithDataSource:self];
  95. _smoothView.delegate = self;
  96. _smoothView.ceilPointHeight = 0;
  97. _smoothView.bottomHover = YES;
  98. _smoothView.allowDragBottom = YES;
  99. _smoothView.allowDragScroll = YES;
  100. // 解决与返回手势滑动冲突
  101. // _smoothView.listCollectionView.gk_openGestureHandle = YES;
  102. _smoothView.holdUpScrollView = YES;
  103. }
  104. return _smoothView;
  105. }
  106. - (UIImageView *)headerView {
  107. if (!_headerView) {
  108. UIImage *image = [UIImage imageNamed:@"douban"];
  109. _headerView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
  110. _headerView.image = image;
  111. }
  112. return _headerView;
  113. }
  114. - (UIView *)segmentedView {
  115. if (!_segmentedView) {
  116. _segmentedView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 60)];
  117. _segmentedView.backgroundColor = [UIColor whiteColor];
  118. [_segmentedView addSubview:self.categoryView];
  119. UIView *topView = [UIView new];
  120. topView.backgroundColor = [UIColor lightGrayColor];
  121. topView.layer.cornerRadius = 3;
  122. topView.layer.masksToBounds = YES;
  123. [_segmentedView addSubview:topView];
  124. [topView mas_makeConstraints:^(MASConstraintMaker *make) {
  125. make.top.equalTo(self->_segmentedView).offset(5);
  126. make.centerX.equalTo(self->_segmentedView);
  127. make.width.mas_equalTo(60);
  128. make.height.mas_equalTo(6);
  129. }];
  130. }
  131. return _segmentedView;
  132. }
  133. - (JXCategorySubTitleView *)categoryView {
  134. if (!_categoryView) {
  135. _categoryView = [[JXCategorySubTitleView alloc] initWithFrame:CGRectMake(0, 10, self.view.frame.size.width, 40)];
  136. _categoryView.backgroundColor = UIColor.whiteColor;
  137. _categoryView.averageCellSpacingEnabled = NO;
  138. _categoryView.contentEdgeInsetLeft = 16;
  139. _categoryView.delegate = self;
  140. _categoryView.titles = @[@"影评", @"讨论"];
  141. _categoryView.titleFont = [UIFont systemFontOfSize:16];
  142. _categoryView.titleColor = UIColor.grayColor;
  143. _categoryView.titleSelectedColor = UIColor.blackColor;
  144. _categoryView.subTitles = @[@"342", @"2004"];
  145. _categoryView.subTitleFont = [UIFont systemFontOfSize:11];
  146. _categoryView.subTitleColor = UIColor.grayColor;
  147. _categoryView.subTitleSelectedColor = UIColor.grayColor;
  148. _categoryView.positionStyle = JXCategorySubTitlePositionStyle_Right;
  149. _categoryView.alignStyle = JXCategorySubTitleAlignStyle_Top;
  150. _categoryView.cellSpacing = 30;
  151. _categoryView.cellWidthIncrement = 0;
  152. _categoryView.ignoreSubTitleWidth = YES;
  153. JXCategoryIndicatorLineView *lineView = [JXCategoryIndicatorLineView new];
  154. lineView.indicatorColor = UIColor.blackColor;
  155. _categoryView.indicators = @[self.lineView];
  156. // _categoryView.contentScrollView = self.smoothView.listCollectionView;
  157. }
  158. return _categoryView;
  159. }
  160. - (JXCategoryIndicatorAlignmentLineView *)lineView {
  161. if (!_lineView) {
  162. _lineView = [JXCategoryIndicatorAlignmentLineView new];
  163. _lineView.indicatorColor = UIColor.blackColor;
  164. }
  165. return _lineView;
  166. }
  167. @end