2025-11-06 19:19:12 +08:00
|
|
|
|
//
|
|
|
|
|
|
// KBShopVC.m
|
|
|
|
|
|
// keyBoard
|
|
|
|
|
|
//
|
|
|
|
|
|
// Created by Mac on 2025/11/6.
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#import "KBShopVC.h"
|
2025-11-09 13:56:13 +08:00
|
|
|
|
#import "JXPagerView.h"
|
|
|
|
|
|
#import "KBShopHeadView.h"
|
|
|
|
|
|
#import <JXCategoryView/JXCategoryView.h>
|
2025-11-09 14:26:02 +08:00
|
|
|
|
#import "KBCategoryTitleView.h"
|
2025-11-09 13:56:13 +08:00
|
|
|
|
#import <JXPagingView/JXPagerView.h>
|
|
|
|
|
|
#import <MJRefresh/MJRefresh.h>
|
|
|
|
|
|
#import "KBShopItemVC.h"
|
2025-11-06 19:19:12 +08:00
|
|
|
|
|
2025-11-09 13:56:13 +08:00
|
|
|
|
static const CGFloat JXTableHeaderViewHeight = (323);
|
|
|
|
|
|
static const CGFloat JXheightForHeaderInSection = 50;
|
2025-11-06 19:19:12 +08:00
|
|
|
|
|
2025-11-09 13:56:13 +08:00
|
|
|
|
@interface KBShopVC ()<JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate,JXCategoryViewDelegate>
|
|
|
|
|
|
@property (nonatomic, strong) UIView *naviBGView;
|
|
|
|
|
|
|
|
|
|
|
|
@property (nonatomic, strong) JXPagerView *pagerView;
|
|
|
|
|
|
@property (nonatomic, strong) KBShopHeadView *userHeaderView;
|
|
|
|
|
|
@property (nonatomic, assign) BOOL isNeedFooter;
|
|
|
|
|
|
@property (nonatomic, assign) BOOL isNeedHeader;
|
|
|
|
|
|
- (JXPagerView *)preferredPagingView;
|
|
|
|
|
|
|
|
|
|
|
|
@property (nonatomic, strong) JXCategoryTitleView *categoryView;
|
|
|
|
|
|
@property (nonatomic, strong) NSArray <NSString *> *titles;
|
2025-11-06 19:19:12 +08:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@implementation KBShopVC
|
|
|
|
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
|
|
[super viewDidLoad];
|
2025-11-09 17:07:43 +08:00
|
|
|
|
[self setupUI];
|
2025-11-09 15:59:18 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
|
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
|
|
|
|
|
|
|
[self.navigationController setNavigationBarHidden:YES animated:YES];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)viewWillDisappear:(BOOL)animated {
|
|
|
|
|
|
[super viewWillDisappear:animated];
|
|
|
|
|
|
|
|
|
|
|
|
[self.navigationController setNavigationBarHidden:NO animated:NO];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)setupUI{
|
|
|
|
|
|
|
2025-11-09 13:56:13 +08:00
|
|
|
|
|
|
|
|
|
|
self.automaticallyAdjustsScrollViewInsets = NO;
|
|
|
|
|
|
self.view.backgroundColor = [UIColor whiteColor];
|
|
|
|
|
|
self.navigationController.navigationBar.translucent = false;
|
|
|
|
|
|
self.edgesForExtendedLayout = UIRectEdgeNone;
|
2025-11-09 15:59:18 +08:00
|
|
|
|
_titles = @[@"能力", @"爱好", @"队友",@"能力2", @"爱好2", @"队友2",@"能力", @"爱好", @"队友",@"能力2", @"爱好2", @"队友2"];
|
2025-11-09 13:56:13 +08:00
|
|
|
|
|
|
|
|
|
|
_userHeaderView = [[KBShopHeadView alloc] init];
|
2025-11-09 14:26:02 +08:00
|
|
|
|
_categoryView = (JXCategoryTitleView *)[[KBCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, JXheightForHeaderInSection)];
|
2025-11-09 13:56:13 +08:00
|
|
|
|
self.categoryView.titles = self.titles;
|
|
|
|
|
|
self.categoryView.backgroundColor = [UIColor whiteColor];
|
|
|
|
|
|
self.categoryView.delegate = self;
|
|
|
|
|
|
self.categoryView.titleSelectedColor = [UIColor colorWithHex:0x1B1F1A];
|
|
|
|
|
|
self.categoryView.titleColor = [UIColor colorWithHex:0x9F9F9F];
|
2025-11-09 14:58:44 +08:00
|
|
|
|
// 左右滑动时不要文字渐变色
|
|
|
|
|
|
self.categoryView.titleColorGradientEnabled = NO;
|
2025-11-09 14:44:31 +08:00
|
|
|
|
// 不需要文字放大效果
|
2025-11-09 17:07:43 +08:00
|
|
|
|
self.categoryView.cellWidthZoomEnabled = NO;
|
|
|
|
|
|
self.categoryView.cellWidthZoomScale = 1.0;
|
2025-11-09 13:56:13 +08:00
|
|
|
|
self.categoryView.contentScrollViewClickTransitionAnimationEnabled = NO;
|
2025-11-09 14:26:02 +08:00
|
|
|
|
// Unselected items need a rounded gray background like the screenshot.
|
|
|
|
|
|
// JXCategoryTitleView supports cell background colors via JXCategoryIndicatorView.
|
|
|
|
|
|
self.categoryView.cellBackgroundColorGradientEnabled = YES;
|
|
|
|
|
|
self.categoryView.cellBackgroundUnselectedColor = [UIColor colorWithHex:0xEFEFEF];
|
|
|
|
|
|
self.categoryView.cellBackgroundSelectedColor = [UIColor whiteColor];
|
|
|
|
|
|
// Make the pills look compact
|
|
|
|
|
|
self.categoryView.cellWidthIncrement = 20; // horizontal padding for each item
|
|
|
|
|
|
self.categoryView.cellSpacing = 12; // spacing between items
|
|
|
|
|
|
self.categoryView.contentEdgeInsetLeft = 16;
|
|
|
|
|
|
self.categoryView.contentEdgeInsetRight = 16;
|
2025-11-09 14:44:31 +08:00
|
|
|
|
self.categoryView.averageCellSpacingEnabled = NO;
|
2025-11-09 13:56:13 +08:00
|
|
|
|
|
|
|
|
|
|
JXCategoryIndicatorBackgroundView *backgroundView = [[JXCategoryIndicatorBackgroundView alloc] init];
|
2025-11-09 15:59:18 +08:00
|
|
|
|
backgroundView.indicatorHeight = 30;
|
2025-11-09 13:56:13 +08:00
|
|
|
|
backgroundView.indicatorCornerRadius = JXCategoryViewAutomaticDimension;
|
2025-11-09 14:26:02 +08:00
|
|
|
|
backgroundView.indicatorColor = [UIColor whiteColor]; // keep selected fill white
|
2025-11-09 13:56:13 +08:00
|
|
|
|
backgroundView.layer.borderColor = [UIColor colorWithHex:0x02BEAC].CGColor;
|
|
|
|
|
|
backgroundView.layer.borderWidth = 1;
|
2025-11-09 17:07:43 +08:00
|
|
|
|
backgroundView.indicatorWidthIncrement = 0; // 指示器宽度不额外加宽
|
2025-11-09 14:58:44 +08:00
|
|
|
|
// 点击切换时不需要左右滚动动画,直接跳转到目标位置
|
|
|
|
|
|
backgroundView.scrollEnabled = NO;
|
|
|
|
|
|
backgroundView.scrollAnimationDuration = 0;
|
2025-11-09 13:56:13 +08:00
|
|
|
|
self.categoryView.indicators = @[backgroundView];
|
|
|
|
|
|
|
|
|
|
|
|
_pagerView = [self preferredPagingView];
|
|
|
|
|
|
self.pagerView.mainTableView.gestureDelegate = self;
|
|
|
|
|
|
[self.view addSubview:self.pagerView];
|
2025-11-09 14:58:44 +08:00
|
|
|
|
// self.pagerView.listContainerView.scrollView.scrollEnabled = false;
|
2025-11-09 14:44:31 +08:00
|
|
|
|
|
2025-11-09 13:56:13 +08:00
|
|
|
|
|
|
|
|
|
|
self.categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
|
|
|
|
|
|
|
|
|
|
|
|
//导航栏隐藏的情况,处理扣边返回,下面的代码要加上
|
|
|
|
|
|
// [self.pagerView.listContainerView.scrollView.panGestureRecognizer requireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer];
|
|
|
|
|
|
// [self.pagerView.mainTableView.panGestureRecognizer requireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer];
|
|
|
|
|
|
|
|
|
|
|
|
__weak typeof(self)weakSelf = self;
|
|
|
|
|
|
self.pagerView.mainTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
|
|
|
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
|
|
|
self.categoryView.titles = @[@"高级能力", @"高级爱好", @"高级队友"];
|
|
|
|
|
|
self.categoryView.defaultSelectedIndex = 0;
|
|
|
|
|
|
[self.categoryView reloadData];
|
|
|
|
|
|
[self.pagerView reloadData];
|
|
|
|
|
|
[weakSelf.pagerView.mainTableView.mj_header endRefreshing];
|
|
|
|
|
|
});
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
self.pagerView.pinSectionHeaderVerticalOffset = KB_NAV_TOTAL_HEIGHT;
|
|
|
|
|
|
|
|
|
|
|
|
self.naviBGView = [[UIView alloc] init];
|
|
|
|
|
|
self.naviBGView.alpha = 0;
|
|
|
|
|
|
self.naviBGView.backgroundColor = [UIColor whiteColor];
|
|
|
|
|
|
self.naviBGView.frame = CGRectMake(0, 0, KB_SCREEN_WIDTH, KB_NAV_TOTAL_HEIGHT);
|
|
|
|
|
|
[self.view addSubview:self.naviBGView];
|
|
|
|
|
|
UILabel *naviTitleLabel = [[UILabel alloc] init];
|
|
|
|
|
|
naviTitleLabel.text = @"导航栏隐藏";
|
|
|
|
|
|
naviTitleLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
|
naviTitleLabel.frame = CGRectMake(0, KB_STATUSBAR_HEIGHT, self.view.bounds.size.width, 44);
|
|
|
|
|
|
[self.naviBGView addSubview:naviTitleLabel];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (JXPagerView *)preferredPagingView {
|
|
|
|
|
|
return [[JXPagerView alloc] initWithDelegate:self];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)viewDidLayoutSubviews {
|
|
|
|
|
|
[super viewDidLayoutSubviews];
|
|
|
|
|
|
|
|
|
|
|
|
self.pagerView.frame = self.view.bounds;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - JXPagerViewDelegate
|
|
|
|
|
|
|
|
|
|
|
|
- (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
|
|
|
|
|
|
return self.userHeaderView;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
|
|
|
|
|
|
return KBFit(JXTableHeaderViewHeight);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
|
|
|
|
|
|
return JXheightForHeaderInSection;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (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 {
|
|
|
|
|
|
KBShopItemVC *list = [[KBShopItemVC alloc] init];
|
|
|
|
|
|
list.title = self.titles[index];
|
|
|
|
|
|
list.isNeedHeader = self.isNeedHeader;
|
|
|
|
|
|
list.isNeedFooter = self.isNeedFooter;
|
|
|
|
|
|
if (index == 0) {
|
|
|
|
|
|
list.dataSource = @[@"橡胶火箭", @"橡胶火箭炮", @"橡胶机关枪", @"橡胶子弹", @"橡胶攻城炮", @"橡胶象枪", @"橡胶象枪乱打", @"橡胶灰熊铳", @"橡胶雷神象枪", @"橡胶猿王枪", @"橡胶犀·榴弹炮", @"橡胶大蛇炮", @"橡胶火箭", @"橡胶火箭炮", @"橡胶机关枪", @"橡胶子弹", @"橡胶攻城炮", @"橡胶象枪", @"橡胶象枪乱打", @"橡胶灰熊铳", @"橡胶雷神象枪", @"橡胶猿王枪", @"橡胶犀·榴弹炮", @"橡胶大蛇炮"].mutableCopy;
|
|
|
|
|
|
}else if (index == 1) {
|
|
|
|
|
|
list.dataSource = @[@"吃烤肉", @"吃鸡腿肉", @"吃牛肉", @"各种肉"].mutableCopy;
|
|
|
|
|
|
}else {
|
|
|
|
|
|
list.dataSource = @[@"【剑士】罗罗诺亚·索隆", @"【航海士】娜美", @"【狙击手】乌索普", @"【厨师】香吉士", @"【船医】托尼托尼·乔巴", @"【船匠】 弗兰奇", @"【音乐家】布鲁克", @"【考古学家】妮可·罗宾"].mutableCopy;
|
|
|
|
|
|
}
|
|
|
|
|
|
return list;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - JXCategoryViewDelegate
|
|
|
|
|
|
|
|
|
|
|
|
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
|
|
|
|
|
|
self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - JXPagerMainTableViewGestureDelegate
|
|
|
|
|
|
|
|
|
|
|
|
- (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
|
|
|
|
|
|
//禁止categoryView左右滑动的时候,上下和左右都可以滚动
|
|
|
|
|
|
if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
|
|
|
|
|
|
return NO;
|
|
|
|
|
|
}
|
|
|
|
|
|
return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
|
2025-11-06 19:19:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-11-09 13:56:13 +08:00
|
|
|
|
- (void)pagerView:(JXPagerView *)pagerView mainTableViewDidScroll:(UIScrollView *)scrollView {
|
|
|
|
|
|
CGFloat thresholdDistance = JXTableHeaderViewHeight;
|
|
|
|
|
|
CGFloat percent = scrollView.contentOffset.y/thresholdDistance;
|
|
|
|
|
|
percent = MAX(0, MIN(1, percent));
|
|
|
|
|
|
self.naviBGView.alpha = percent;
|
2025-11-06 19:19:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|