RQVipCenterViewController.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. //
  2. // RQVipCenterViewController.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2022/8/5.
  6. // Copyright © 2022 JCZ. All rights reserved.
  7. //
  8. #import "RQVipCenterViewController.h"
  9. @interface RQHeaderScrollView : UIView
  10. @property (nonatomic, readwrite, strong) UIScrollView *scrollView;
  11. @property (nonatomic, readwrite, assign) RQHomePageSubjectType historyHomePageSubjectType;
  12. @end
  13. @implementation RQHeaderScrollView
  14. - (id)initWithFrame:(CGRect)frame typeModels:(NSArray *)typeModels {
  15. self = [super initWithFrame:frame];
  16. if (self) {
  17. self.backgroundColor = RQColorFromHexString(@"#2C2D3C");
  18. [self addSubview:self.scrollView];
  19. self.clipsToBounds = YES;
  20. CGFloat vipCenterView_weight = RQ_FIT_HORIZONTAL(208.f);
  21. CGFloat vipCenterView_height = RQ_FIT_HORIZONTAL(102.f);
  22. CGFloat vipCenterView_space = RQ_FIT_HORIZONTAL(10.f);
  23. self.scrollView.contentSize = CGSizeMake((vipCenterView_weight * 4) + (vipCenterView_space * 5), 13.f + vipCenterView_height + 15.f);
  24. for (int i = 0; i < 4; i ++) {
  25. RQVipCenterItemView *vipCenterItemView = [RQVipCenterItemView rqVipCenterItemView];
  26. vipCenterItemView.typeModels = typeModels;
  27. vipCenterItemView.homePageSubjectType = i;
  28. vipCenterItemView.openVipBtn.tag = i;
  29. vipCenterItemView.continueBtn.tag = i;
  30. // [vipCenterItemView.openVipBtn addTarget:self action:@selector(openBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  31. // [vipCenterItemView.continueBtn addTarget:self action:@selector(continueBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  32. vipCenterItemView.frame = CGRectMake(vipCenterView_weight * i + vipCenterView_space * (i+1), 13.f, vipCenterView_weight, vipCenterView_height);
  33. vipCenterItemView.arrowToLeft.constant = (RQ_SCREEN_WIDTH / 4.f) * 0.5;
  34. vipCenterItemView.userInteractionEnabled = YES;
  35. // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
  36. // [vipCenterItemView addGestureRecognizer:tap];
  37. [self.scrollView addSubview:vipCenterItemView];
  38. self.historyHomePageSubjectType = RQ_YDTQuestion_Module.subject;
  39. [vipCenterItemView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  40. [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full subject:i];
  41. }];
  42. }
  43. }
  44. return self;
  45. }
  46. //- (void)openBtnAction:(id)sender {
  47. // QMUIButton *btn = (QMUIButton *)sender;
  48. // RQHomePageSubjectType subject = btn.tag;
  49. // self.historyHomePageSubjectType = subject;
  50. // [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full subject:subject];
  51. //}
  52. //
  53. //- (void)continueBtnAction:(id)sender {
  54. // QMUIButton *btn = (QMUIButton *)sender;
  55. // RQHomePageSubjectType subject = btn.tag;
  56. // self.historyHomePageSubjectType = subject;
  57. // [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full subject:subject];
  58. //}
  59. //- (void)tapAction:(UITapGestureRecognizer *)tap {
  60. // NSLog(@"你点到我了");
  61. //}
  62. - (UIScrollView *)scrollView {
  63. if (!_scrollView) {
  64. _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, RQ_FIT_HORIZONTAL(208.f) + 10.f, RQ_FIT_HORIZONTAL(108.f) + 32.f)];
  65. _scrollView.backgroundColor = RQColorFromHexString(@"#2C2D3C");
  66. _scrollView.contentInset = UIEdgeInsetsMake(0, 10.f, 0, 0);
  67. _scrollView.pagingEnabled = YES;
  68. _scrollView.clipsToBounds = NO;
  69. _scrollView.showsVerticalScrollIndicator = NO;
  70. _scrollView.showsHorizontalScrollIndicator = NO;
  71. _scrollView.bouncesZoom = NO;
  72. }
  73. return _scrollView;
  74. }
  75. - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
  76. UIView *view = [super hitTest:point withEvent:event];
  77. if ([view isEqual:self]) {
  78. for (UIView *subview in self.scrollView.subviews) {
  79. CGPoint offset = CGPointMake(point.x - self.scrollView.frame.origin.x + self.scrollView.contentOffset.x - subview.frame.origin.x,
  80. point.y - self.scrollView.frame.origin.y + self.scrollView.contentOffset.y - subview.frame.origin.y);
  81. if ((view = [subview hitTest:offset withEvent:event])) {
  82. return view;
  83. }
  84. }
  85. return self.scrollView;
  86. }
  87. return view;
  88. }
  89. @end
  90. @interface RQVipCenterViewController () <JXCategoryViewDelegate, JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate, UIScrollViewDelegate>
  91. /// viewModel
  92. @property (nonatomic, readonly, strong) RQVipCenterViewModel *viewModel;
  93. @property (nonatomic, readwrite, strong) JXPagerView *pagerView;
  94. @property (nonatomic, readwrite, strong) JXCategoryTitleView *categoryView;
  95. //@property (nonatomic, readwrite, strong) SDCycleScrollView *cycleScrollView;
  96. @property (nonatomic, readwrite, strong) NSArray <NSString *> *titles;
  97. @property (nonatomic, readwrite, strong) NSArray <NSString *> *imagesArr;
  98. @property (nonatomic, readwrite, strong) NSArray <NSString *> *isVipimagesArr;
  99. @property (nonatomic, readwrite, strong) NSArray <NSString *> *noimagesArr;
  100. @property (nonatomic, readwrite, assign) BOOL isCycleScroll;
  101. @property (nonatomic, readwrite, assign) BOOL isPagerScroll;
  102. @property (nonatomic, readwrite, assign) RQHomePageSubjectType historyHomePageSubjectType;
  103. @property (nonatomic, readwrite, strong) RQHeaderScrollView *myScrollView;
  104. @property (nonatomic, readwrite, strong) RQVipCenterHeaderView *vipCenterHeaderView;
  105. @end
  106. @implementation RQVipCenterViewController
  107. @dynamic viewModel;
  108. #pragma mark - SystemMethod
  109. - (void)viewDidLoad {
  110. /// 初始化
  111. [self rq_setup];
  112. }
  113. - (void)viewWillAppear:(BOOL)animated {
  114. [super viewWillAppear:animated];
  115. @weakify(self)
  116. CGFloat vipCenterView_weight = RQ_FIT_HORIZONTAL(208.f);
  117. CGFloat vipCenterView_space = RQ_FIT_HORIZONTAL(10.f);
  118. CGFloat offsetX = (vipCenterView_weight * self.myScrollView.historyHomePageSubjectType) + (vipCenterView_space * (self.myScrollView.historyHomePageSubjectType));
  119. CGFloat offsetX_1 = (RQ_SCREEN_WIDTH / 4.f) * (self.myScrollView.historyHomePageSubjectType);
  120. [self.myScrollView.scrollView setContentOffset:CGPointMake(offsetX, 0) animated:YES];
  121. [[RACScheduler mainThreadScheduler] afterDelay:0.1 schedule:^{
  122. @strongify(self)
  123. [self.vipCenterHeaderView.bottomScrolView setContentOffset:CGPointMake(offsetX_1, 0) animated:YES];
  124. }];
  125. }
  126. - (void)viewDidLayoutSubviews {
  127. [super viewDidLayoutSubviews];
  128. self.pagerView.frame = CGRectMake(0, RQ_APPLICATION_STATUS_BAR_HEIGHT + RQ_APPLICATION_NAV_BAR_HEIGHT, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - RQ_APPLICATION_STATUS_BAR_HEIGHT - RQ_APPLICATION_NAV_BAR_HEIGHT - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT);
  129. }
  130. - (void)dealloc {
  131. self.myScrollView.scrollView.delegate = nil;
  132. self.vipCenterHeaderView.bottomScrolView.delegate = nil;
  133. self.categoryView.delegate = nil;
  134. }
  135. #pragma mark - PrivateMethods
  136. /// 初始化
  137. - (void)rq_setup {
  138. /// set up ...
  139. @weakify(self)
  140. [self.view addSubview:self.pagerView];
  141. self.myScrollView.scrollView.delegate = self;
  142. [self.pagerView.listContainerView addSubview:self.myScrollView];
  143. self.pagerView.defaultSelectedIndex = self.viewModel.homePageSubjectType;
  144. self.categoryView.defaultSelectedIndex = self.viewModel.homePageSubjectType;
  145. [self.pagerView reloadData];
  146. [self.categoryView reloadData];
  147. // CGFloat vipCenterView_weight = RQ_FIT_HORIZONTAL(208.f);
  148. // CGFloat vipCenterView_space = RQ_FIT_HORIZONTAL(10.f);
  149. //
  150. // CGFloat offsetX = (vipCenterView_weight * self.viewModel.homePageSubjectType) + (vipCenterView_space * (self.viewModel.homePageSubjectType));
  151. // CGFloat offsetX_1 = (RQ_SCREEN_WIDTH / 4.f) * (self.viewModel.homePageSubjectType);
  152. // [self.myScrollView.scrollView setContentOffset:CGPointMake(offsetX, 0) animated:YES];
  153. // [[RACScheduler mainThreadScheduler] afterDelay:0.1 schedule:^{
  154. // @strongify(self)
  155. // [self.vipCenterHeaderView.bottomScrolView setContentOffset:CGPointMake(offsetX_1, 0) animated:YES];
  156. // }];
  157. }
  158. #pragma mark - JXPagerViewDelegate
  159. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  160. return self.vipCenterHeaderView;
  161. }
  162. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  163. return 126.f;
  164. }
  165. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  166. return 0.f;
  167. }
  168. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  169. return self.categoryView;
  170. }
  171. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  172. //和categoryView的item数量一致
  173. return self.categoryView.titles.count;
  174. }
  175. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
  176. RQVipCenterSubViewModel *vipCenterSubViewModel = [[RQVipCenterSubViewModel alloc] initWithServices:self.viewModel.services params:@{RQHomePageSubjectTypeKey : @(index)}];
  177. RQVipCenterSubViewController *vipCenterSubViewController = [[RQVipCenterSubViewController alloc] initWithViewModel:vipCenterSubViewModel];
  178. NSArray *arr = self.myScrollView.scrollView.subviews;
  179. CGFloat offsetX_1 = (RQ_SCREEN_WIDTH / 4.f) * index;
  180. RQVipCenterItemView *vipCenterItemView = arr[index];
  181. vipCenterItemView.arrowImageView.hidden = NO;
  182. [self.vipCenterHeaderView.bottomScrolView setContentOffset:CGPointMake(offsetX_1, 0) animated:YES];
  183. return vipCenterSubViewController;
  184. }
  185. #pragma mark - JXCategoryViewDelegate
  186. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  187. self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
  188. _isPagerScroll = YES;
  189. NSArray *arr = self.myScrollView.scrollView.subviews;
  190. CGFloat vipCenterView_weight = RQ_FIT_HORIZONTAL(208.f);
  191. CGFloat vipCenterView_weight_1 = (RQ_SCREEN_WIDTH / 4.f);
  192. CGFloat vipCenterView_space = RQ_FIT_HORIZONTAL(10.f);
  193. CGFloat offsetX = (vipCenterView_weight * index) + (vipCenterView_space * (index));
  194. CGFloat offsetX_1 = (vipCenterView_weight_1 * index);
  195. [self.myScrollView.scrollView setContentOffset:CGPointMake(offsetX, 0) animated:YES];
  196. [self.vipCenterHeaderView.bottomScrolView setContentOffset:CGPointMake(offsetX_1, 0) animated:YES];
  197. self.vipCenterHeaderView.homePageSubjectType = index;
  198. RQVipCenterItemView *vipCenterItemView = arr[index];
  199. vipCenterItemView.arrowImageView.hidden = NO;
  200. }
  201. - (void)categoryView:(JXCategoryBaseView *)categoryView scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio {
  202. NSArray *arr = self.myScrollView.scrollView.subviews;
  203. RQVipCenterItemView *vipCenterItemLeftView = arr[leftIndex];
  204. vipCenterItemLeftView.arrowImageView.hidden = YES;
  205. RQVipCenterItemView *vipCenterItemRightView = arr[rightIndex];
  206. vipCenterItemRightView.arrowImageView.hidden = YES;
  207. }
  208. - (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
  209. }
  210. - (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index {
  211. }
  212. #pragma mark - JXPagerMainTableViewGestureDelegate
  213. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  214. if ([self checkIsNestContentScrollView:(UIScrollView *)gestureRecognizer.view] || [self checkIsNestContentScrollView:(UIScrollView *)otherGestureRecognizer.view]) {
  215. //如果交互的是嵌套的contentScrollView,证明在左右滑动,就不允许同时响应
  216. return NO;
  217. }
  218. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  219. }
  220. - (BOOL)checkIsNestContentScrollView:(UIScrollView *)scrollView {
  221. for (RQHomeSubPageViewController *list in self.pagerView.validListDict.allValues) {
  222. if (list.contentScrollView == scrollView) {
  223. return YES;
  224. }
  225. }
  226. return NO;
  227. }
  228. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  229. NSArray *arr = scrollView.subviews;
  230. CGFloat page = scrollView.contentOffset.x / scrollView.bounds.size.width;
  231. NSInteger pageIndex = [NSNumber numberWithFloat:page + 0.5].integerValue;
  232. RQVipCenterItemView *vipCenterItemView = arr[pageIndex];
  233. vipCenterItemView.arrowImageView.hidden = YES;
  234. }
  235. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  236. CGFloat page = scrollView.contentOffset.x / scrollView.bounds.size.width;
  237. NSInteger pageIndex = [NSNumber numberWithFloat:page + 0.5].integerValue;
  238. [self.categoryView selectCellAtIndex:pageIndex selectedType:JXCategoryCellSelectedTypeClick];
  239. }
  240. #pragma mark - LazyLoad
  241. - (JXPagerView *)pagerView {
  242. if (!_pagerView) {
  243. _pagerView = [[JXPagerView alloc] initWithDelegate:self];
  244. _pagerView.mainTableView.gestureDelegate = self;
  245. _pagerView.listContainerView.categoryNestPagingEnabled = YES;
  246. _pagerView.mainTableView.bounces = NO;
  247. _pagerView.defaultSelectedIndex = 0;
  248. _pagerView.listContainerView.frame = CGRectMake(0, RQ_FIT_HORIZONTAL(102.f) + 32.f, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - RQ_APPLICATION_NAV_BAR_HEIGHT - RQ_APPLICATION_STATUS_BAR_HEIGHT - 88.f - RQ_FIT_HORIZONTAL(102.f) - 32.f - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT);
  249. }
  250. return _pagerView;
  251. }
  252. - (JXCategoryTitleView *)categoryView {
  253. if (!_categoryView) {
  254. _categoryView = [[JXCategoryTitleView alloc] init];
  255. _categoryView.titles = self.titles;
  256. _categoryView.backgroundColor = RQColorFromHexString(@"#2C2D3C");
  257. _categoryView.titleSelectedColor = RQColorFromHexString(@"#F9BF7D");
  258. _categoryView.titleColor = RQColorFromHexString(@"#F9BF7D");
  259. _categoryView.titleFont = RQRegularFont(13);
  260. _categoryView.titleSelectedFont = RQRegularFont(13);
  261. _categoryView.titleColorGradientEnabled = YES;
  262. _categoryView.titleLabelZoomEnabled = YES;
  263. _categoryView.contentScrollViewClickTransitionAnimationEnabled = YES;
  264. _categoryView.titleLabelZoomSelectedVerticalOffset = 0.0f;
  265. JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
  266. lineView.indicatorHeight = 14.f;
  267. lineView.verticalMargin = 0;
  268. lineView.indicatorColor = UIColor.clearColor;
  269. lineView.indicatorWidth = 14.f;
  270. lineView.componentPosition = JXCategoryComponentPosition_Top;
  271. UIImageView *vip = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, RQ_FIT_HORIZONTAL(14.f), RQ_FIT_HORIZONTAL(14.f))];
  272. vip.image = RQImageNamed(@"vip点");
  273. [lineView addSubview:vip];
  274. _categoryView.indicators = @[lineView];
  275. _categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
  276. _categoryView.delegate = self;
  277. }
  278. return _categoryView;
  279. }
  280. - (RQHeaderScrollView *)myScrollView {
  281. if (!_myScrollView) {
  282. _myScrollView = [[RQHeaderScrollView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_FIT_HORIZONTAL(108.f) + 32.f) typeModels:self.viewModel.typeModels];
  283. }
  284. return _myScrollView;
  285. }
  286. - (RQVipCenterHeaderView *)vipCenterHeaderView {
  287. if (!_vipCenterHeaderView) {
  288. _vipCenterHeaderView = [RQVipCenterHeaderView rqVipCenterHeaderView];
  289. CGFloat vipCenterHeaderViewItem_weight = (RQ_SCREEN_WIDTH / 4.f);
  290. // CGFloat vipCenterHeaderViewItem_weight_half = vipCenterHeaderViewItem_weight * 0.5;
  291. NSArray *arr = @[@"科一",@"科二",@"科三",@"科四"];
  292. _vipCenterHeaderView.bottomScrolView.contentSize = CGSizeMake(vipCenterHeaderViewItem_weight * arr.count, 40.f);
  293. for (int i = 0; i < 4; i ++) {
  294. RQVipCenterHeaderItemView *vipCenterHeaderItemView = [RQVipCenterHeaderItemView rqVipCenterHeaderItemViewWithFrame:CGRectMake(vipCenterHeaderViewItem_weight * i, 0, vipCenterHeaderViewItem_weight, 40.f)];
  295. vipCenterHeaderItemView.myVipSubjectTitleLabel.text = arr[i];
  296. vipCenterHeaderItemView.lastImg.hidden = (i == (arr.count - 1));
  297. [_vipCenterHeaderView.bottomScrolView addSubview:vipCenterHeaderItemView];
  298. }
  299. }
  300. return _vipCenterHeaderView;
  301. }
  302. - (NSArray<NSString *> *)titles {
  303. return @[@"科一", @"科二", @"科三", @"科四"];
  304. }
  305. - (NSArray<NSString *> *)imagesArr {
  306. return @[@"科目一会员中心", @"科目二会员中心", @"科目三会员中心", @"科目四会员中心"];
  307. }
  308. - (NSArray<NSString *> *)isVipimagesArr {
  309. return @[@"科一金", @"科二金", @"科三金", @"科四金"];
  310. }
  311. - (NSArray<NSString *> *)noimagesArr {
  312. return @[@"科一银", @"科二银", @"科三银", @"科四银"];
  313. }
  314. @end