123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- //
- // RQVipCenterViewController.m
- // jiaPei
- //
- // Created by 张嵘 on 2022/8/5.
- // Copyright © 2022 JCZ. All rights reserved.
- //
- #import "RQVipCenterViewController.h"
- @interface RQHeaderScrollView : UIView
- @property (nonatomic, readwrite, strong) UIScrollView *scrollView;
- @property (nonatomic, readwrite, assign) RQHomePageSubjectType historyHomePageSubjectType;
- @end
- @implementation RQHeaderScrollView
- - (id)initWithFrame:(CGRect)frame typeModels:(NSArray *)typeModels {
- self = [super initWithFrame:frame];
- if (self) {
- self.backgroundColor = RQColorFromHexString(@"#2C2D3C");
- [self addSubview:self.scrollView];
- self.clipsToBounds = YES;
-
- CGFloat vipCenterView_weight = RQ_FIT_HORIZONTAL(208.f);
- CGFloat vipCenterView_height = RQ_FIT_HORIZONTAL(102.f);
- CGFloat vipCenterView_space = RQ_FIT_HORIZONTAL(10.f);
- self.scrollView.contentSize = CGSizeMake((vipCenterView_weight * 4) + (vipCenterView_space * 5), 13.f + vipCenterView_height + 15.f);
-
- for (int i = 0; i < 4; i ++) {
- RQVipCenterItemView *vipCenterItemView = [RQVipCenterItemView rqVipCenterItemView];
- vipCenterItemView.typeModels = typeModels;
- vipCenterItemView.homePageSubjectType = i;
- vipCenterItemView.openVipBtn.tag = i;
- vipCenterItemView.continueBtn.tag = i;
- // [vipCenterItemView.openVipBtn addTarget:self action:@selector(openBtnAction:) forControlEvents:UIControlEventTouchUpInside];
- // [vipCenterItemView.continueBtn addTarget:self action:@selector(continueBtnAction:) forControlEvents:UIControlEventTouchUpInside];
- vipCenterItemView.frame = CGRectMake(vipCenterView_weight * i + vipCenterView_space * (i+1), 13.f, vipCenterView_weight, vipCenterView_height);
- vipCenterItemView.arrowToLeft.constant = (RQ_SCREEN_WIDTH / 4.f) * 0.5;
- vipCenterItemView.userInteractionEnabled = YES;
- // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
- // [vipCenterItemView addGestureRecognizer:tap];
- [self.scrollView addSubview:vipCenterItemView];
- self.historyHomePageSubjectType = RQ_YDTQuestion_Module.subject;
- [vipCenterItemView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
- [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full subject:i];
- }];
- }
- }
- return self;
- }
- //- (void)openBtnAction:(id)sender {
- // QMUIButton *btn = (QMUIButton *)sender;
- // RQHomePageSubjectType subject = btn.tag;
- // self.historyHomePageSubjectType = subject;
- // [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full subject:subject];
- //}
- //
- //- (void)continueBtnAction:(id)sender {
- // QMUIButton *btn = (QMUIButton *)sender;
- // RQHomePageSubjectType subject = btn.tag;
- // self.historyHomePageSubjectType = subject;
- // [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full subject:subject];
- //}
- //- (void)tapAction:(UITapGestureRecognizer *)tap {
- // NSLog(@"你点到我了");
- //}
- - (UIScrollView *)scrollView {
- if (!_scrollView) {
- _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, RQ_FIT_HORIZONTAL(208.f) + 10.f, RQ_FIT_HORIZONTAL(108.f) + 32.f)];
- _scrollView.backgroundColor = RQColorFromHexString(@"#2C2D3C");
- _scrollView.contentInset = UIEdgeInsetsMake(0, 10.f, 0, 0);
- _scrollView.pagingEnabled = YES;
- _scrollView.clipsToBounds = NO;
- _scrollView.showsVerticalScrollIndicator = NO;
- _scrollView.showsHorizontalScrollIndicator = NO;
- _scrollView.bouncesZoom = NO;
- }
- return _scrollView;
- }
- - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
- UIView *view = [super hitTest:point withEvent:event];
- if ([view isEqual:self]) {
- for (UIView *subview in self.scrollView.subviews) {
- CGPoint offset = CGPointMake(point.x - self.scrollView.frame.origin.x + self.scrollView.contentOffset.x - subview.frame.origin.x,
- point.y - self.scrollView.frame.origin.y + self.scrollView.contentOffset.y - subview.frame.origin.y);
-
- if ((view = [subview hitTest:offset withEvent:event])) {
- return view;
- }
- }
- return self.scrollView;
- }
- return view;
- }
- @end
- @interface RQVipCenterViewController () <JXCategoryViewDelegate, JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate, UIScrollViewDelegate>
- /// viewModel
- @property (nonatomic, readonly, strong) RQVipCenterViewModel *viewModel;
- @property (nonatomic, readwrite, strong) JXPagerView *pagerView;
- @property (nonatomic, readwrite, strong) JXCategoryTitleView *categoryView;
- //@property (nonatomic, readwrite, strong) SDCycleScrollView *cycleScrollView;
- @property (nonatomic, readwrite, strong) NSArray <NSString *> *titles;
- @property (nonatomic, readwrite, strong) NSArray <NSString *> *imagesArr;
- @property (nonatomic, readwrite, strong) NSArray <NSString *> *isVipimagesArr;
- @property (nonatomic, readwrite, strong) NSArray <NSString *> *noimagesArr;
- @property (nonatomic, readwrite, assign) BOOL isCycleScroll;
- @property (nonatomic, readwrite, assign) BOOL isPagerScroll;
- @property (nonatomic, readwrite, assign) RQHomePageSubjectType historyHomePageSubjectType;
- @property (nonatomic, readwrite, strong) RQHeaderScrollView *myScrollView;
- @property (nonatomic, readwrite, strong) RQVipCenterHeaderView *vipCenterHeaderView;
- @end
- @implementation RQVipCenterViewController
- @dynamic viewModel;
- #pragma mark - SystemMethod
- - (void)viewDidLoad {
- /// 初始化
- [self rq_setup];
-
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- @weakify(self)
- CGFloat vipCenterView_weight = RQ_FIT_HORIZONTAL(208.f);
- CGFloat vipCenterView_space = RQ_FIT_HORIZONTAL(10.f);
- CGFloat offsetX = (vipCenterView_weight * self.myScrollView.historyHomePageSubjectType) + (vipCenterView_space * (self.myScrollView.historyHomePageSubjectType));
- CGFloat offsetX_1 = (RQ_SCREEN_WIDTH / 4.f) * (self.myScrollView.historyHomePageSubjectType);
- [self.myScrollView.scrollView setContentOffset:CGPointMake(offsetX, 0) animated:YES];
- [[RACScheduler mainThreadScheduler] afterDelay:0.1 schedule:^{
- @strongify(self)
- [self.vipCenterHeaderView.bottomScrolView setContentOffset:CGPointMake(offsetX_1, 0) animated:YES];
- }];
- }
- - (void)viewDidLayoutSubviews {
- [super viewDidLayoutSubviews];
- 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);
- }
- - (void)dealloc {
- self.myScrollView.scrollView.delegate = nil;
- self.vipCenterHeaderView.bottomScrolView.delegate = nil;
- self.categoryView.delegate = nil;
- }
- #pragma mark - PrivateMethods
- /// 初始化
- - (void)rq_setup {
- /// set up ...
- @weakify(self)
- [self.view addSubview:self.pagerView];
- self.myScrollView.scrollView.delegate = self;
- [self.pagerView.listContainerView addSubview:self.myScrollView];
- self.pagerView.defaultSelectedIndex = self.viewModel.homePageSubjectType;
- self.categoryView.defaultSelectedIndex = self.viewModel.homePageSubjectType;
- [self.pagerView reloadData];
- [self.categoryView reloadData];
-
- // CGFloat vipCenterView_weight = RQ_FIT_HORIZONTAL(208.f);
- // CGFloat vipCenterView_space = RQ_FIT_HORIZONTAL(10.f);
- //
- // CGFloat offsetX = (vipCenterView_weight * self.viewModel.homePageSubjectType) + (vipCenterView_space * (self.viewModel.homePageSubjectType));
- // CGFloat offsetX_1 = (RQ_SCREEN_WIDTH / 4.f) * (self.viewModel.homePageSubjectType);
- // [self.myScrollView.scrollView setContentOffset:CGPointMake(offsetX, 0) animated:YES];
- // [[RACScheduler mainThreadScheduler] afterDelay:0.1 schedule:^{
- // @strongify(self)
- // [self.vipCenterHeaderView.bottomScrolView setContentOffset:CGPointMake(offsetX_1, 0) animated:YES];
- // }];
- }
- #pragma mark - JXPagerViewDelegate
- - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
- return self.vipCenterHeaderView;
- }
- - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
- return 126.f;
- }
- - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
- return 0.f;
- }
- - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
- return self.categoryView;
- }
- - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
- //和categoryView的item数量一致
- return self.categoryView.titles.count;
- }
- - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
- RQVipCenterSubViewModel *vipCenterSubViewModel = [[RQVipCenterSubViewModel alloc] initWithServices:self.viewModel.services params:@{RQHomePageSubjectTypeKey : @(index)}];
- RQVipCenterSubViewController *vipCenterSubViewController = [[RQVipCenterSubViewController alloc] initWithViewModel:vipCenterSubViewModel];
-
- NSArray *arr = self.myScrollView.scrollView.subviews;
- CGFloat offsetX_1 = (RQ_SCREEN_WIDTH / 4.f) * index;
- RQVipCenterItemView *vipCenterItemView = arr[index];
- vipCenterItemView.arrowImageView.hidden = NO;
- [self.vipCenterHeaderView.bottomScrolView setContentOffset:CGPointMake(offsetX_1, 0) animated:YES];
- return vipCenterSubViewController;
- }
- #pragma mark - JXCategoryViewDelegate
- - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
- self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
- _isPagerScroll = YES;
- NSArray *arr = self.myScrollView.scrollView.subviews;
- CGFloat vipCenterView_weight = RQ_FIT_HORIZONTAL(208.f);
- CGFloat vipCenterView_weight_1 = (RQ_SCREEN_WIDTH / 4.f);
- CGFloat vipCenterView_space = RQ_FIT_HORIZONTAL(10.f);
- CGFloat offsetX = (vipCenterView_weight * index) + (vipCenterView_space * (index));
- CGFloat offsetX_1 = (vipCenterView_weight_1 * index);
- [self.myScrollView.scrollView setContentOffset:CGPointMake(offsetX, 0) animated:YES];
- [self.vipCenterHeaderView.bottomScrolView setContentOffset:CGPointMake(offsetX_1, 0) animated:YES];
- self.vipCenterHeaderView.homePageSubjectType = index;
- RQVipCenterItemView *vipCenterItemView = arr[index];
- vipCenterItemView.arrowImageView.hidden = NO;
- }
- - (void)categoryView:(JXCategoryBaseView *)categoryView scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio {
- NSArray *arr = self.myScrollView.scrollView.subviews;
- RQVipCenterItemView *vipCenterItemLeftView = arr[leftIndex];
- vipCenterItemLeftView.arrowImageView.hidden = YES;
- RQVipCenterItemView *vipCenterItemRightView = arr[rightIndex];
- vipCenterItemRightView.arrowImageView.hidden = YES;
- }
- - (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
-
- }
- - (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index {
-
- }
- #pragma mark - JXPagerMainTableViewGestureDelegate
- - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
- if ([self checkIsNestContentScrollView:(UIScrollView *)gestureRecognizer.view] || [self checkIsNestContentScrollView:(UIScrollView *)otherGestureRecognizer.view]) {
- //如果交互的是嵌套的contentScrollView,证明在左右滑动,就不允许同时响应
- return NO;
- }
- return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
- }
- - (BOOL)checkIsNestContentScrollView:(UIScrollView *)scrollView {
- for (RQHomeSubPageViewController *list in self.pagerView.validListDict.allValues) {
- if (list.contentScrollView == scrollView) {
- return YES;
- }
- }
- return NO;
- }
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
- NSArray *arr = scrollView.subviews;
- CGFloat page = scrollView.contentOffset.x / scrollView.bounds.size.width;
- NSInteger pageIndex = [NSNumber numberWithFloat:page + 0.5].integerValue;
- RQVipCenterItemView *vipCenterItemView = arr[pageIndex];
- vipCenterItemView.arrowImageView.hidden = YES;
- }
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
- CGFloat page = scrollView.contentOffset.x / scrollView.bounds.size.width;
- NSInteger pageIndex = [NSNumber numberWithFloat:page + 0.5].integerValue;
- [self.categoryView selectCellAtIndex:pageIndex selectedType:JXCategoryCellSelectedTypeClick];
- }
- #pragma mark - LazyLoad
- - (JXPagerView *)pagerView {
- if (!_pagerView) {
- _pagerView = [[JXPagerView alloc] initWithDelegate:self];
- _pagerView.mainTableView.gestureDelegate = self;
- _pagerView.listContainerView.categoryNestPagingEnabled = YES;
- _pagerView.mainTableView.bounces = NO;
- _pagerView.defaultSelectedIndex = 0;
- _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);
- }
- return _pagerView;
- }
- - (JXCategoryTitleView *)categoryView {
- if (!_categoryView) {
- _categoryView = [[JXCategoryTitleView alloc] init];
- _categoryView.titles = self.titles;
- _categoryView.backgroundColor = RQColorFromHexString(@"#2C2D3C");
- _categoryView.titleSelectedColor = RQColorFromHexString(@"#F9BF7D");
- _categoryView.titleColor = RQColorFromHexString(@"#F9BF7D");
- _categoryView.titleFont = RQRegularFont(13);
- _categoryView.titleSelectedFont = RQRegularFont(13);
- _categoryView.titleColorGradientEnabled = YES;
- _categoryView.titleLabelZoomEnabled = YES;
- _categoryView.contentScrollViewClickTransitionAnimationEnabled = YES;
- _categoryView.titleLabelZoomSelectedVerticalOffset = 0.0f;
-
-
- JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
- lineView.indicatorHeight = 14.f;
- lineView.verticalMargin = 0;
- lineView.indicatorColor = UIColor.clearColor;
- lineView.indicatorWidth = 14.f;
- lineView.componentPosition = JXCategoryComponentPosition_Top;
- UIImageView *vip = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, RQ_FIT_HORIZONTAL(14.f), RQ_FIT_HORIZONTAL(14.f))];
- vip.image = RQImageNamed(@"vip点");
- [lineView addSubview:vip];
- _categoryView.indicators = @[lineView];
-
- _categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
- _categoryView.delegate = self;
- }
- return _categoryView;
- }
- - (RQHeaderScrollView *)myScrollView {
- if (!_myScrollView) {
- _myScrollView = [[RQHeaderScrollView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_FIT_HORIZONTAL(108.f) + 32.f) typeModels:self.viewModel.typeModels];
- }
- return _myScrollView;
- }
- - (RQVipCenterHeaderView *)vipCenterHeaderView {
- if (!_vipCenterHeaderView) {
- _vipCenterHeaderView = [RQVipCenterHeaderView rqVipCenterHeaderView];
- CGFloat vipCenterHeaderViewItem_weight = (RQ_SCREEN_WIDTH / 4.f);
- // CGFloat vipCenterHeaderViewItem_weight_half = vipCenterHeaderViewItem_weight * 0.5;
- NSArray *arr = @[@"科一",@"科二",@"科三",@"科四"];
- _vipCenterHeaderView.bottomScrolView.contentSize = CGSizeMake(vipCenterHeaderViewItem_weight * arr.count, 40.f);
- for (int i = 0; i < 4; i ++) {
- RQVipCenterHeaderItemView *vipCenterHeaderItemView = [RQVipCenterHeaderItemView rqVipCenterHeaderItemViewWithFrame:CGRectMake(vipCenterHeaderViewItem_weight * i, 0, vipCenterHeaderViewItem_weight, 40.f)];
- vipCenterHeaderItemView.myVipSubjectTitleLabel.text = arr[i];
- vipCenterHeaderItemView.lastImg.hidden = (i == (arr.count - 1));
- [_vipCenterHeaderView.bottomScrolView addSubview:vipCenterHeaderItemView];
- }
-
- }
- return _vipCenterHeaderView;
- }
- - (NSArray<NSString *> *)titles {
- return @[@"科一", @"科二", @"科三", @"科四"];
- }
- - (NSArray<NSString *> *)imagesArr {
- return @[@"科目一会员中心", @"科目二会员中心", @"科目三会员中心", @"科目四会员中心"];
- }
- - (NSArray<NSString *> *)isVipimagesArr {
- return @[@"科一金", @"科二金", @"科三金", @"科四金"];
- }
- - (NSArray<NSString *> *)noimagesArr {
- return @[@"科一银", @"科二银", @"科三银", @"科四银"];
- }
- @end
|