205 lines
6.6 KiB
Objective-C
205 lines
6.6 KiB
Objective-C
//
|
||
// KBAIMessageVC.m
|
||
// keyBoard
|
||
//
|
||
// Created by Mac on 2026/1/28.
|
||
//
|
||
|
||
#import "KBAIMessageVC.h"
|
||
#import <JXCategoryView/JXCategoryView.h>
|
||
#import "KBAIMessageZanVC.h"
|
||
#import "KBAIMessageChatingVC.h"
|
||
#import <Masonry/Masonry.h>
|
||
|
||
@interface KBAIMessageVC () <JXCategoryViewDelegate, JXCategoryListContainerViewDelegate>
|
||
|
||
/// 背景图
|
||
@property (nonatomic, strong) UIImageView *backgroundImageView;
|
||
|
||
/// 分类标签视图
|
||
@property (nonatomic, strong) JXCategoryTitleView *categoryView;
|
||
|
||
/// 列表容器
|
||
@property (nonatomic, strong) JXCategoryListContainerView *listContainerView;
|
||
|
||
/// 右侧搜索按钮
|
||
//@property (nonatomic, strong) UIButton *searchButton;
|
||
|
||
/// 标题数组
|
||
@property (nonatomic, strong) NSArray<NSString *> *titles;
|
||
|
||
@end
|
||
|
||
@implementation KBAIMessageVC
|
||
|
||
#pragma mark - Lifecycle
|
||
|
||
- (void)viewDidLoad {
|
||
[super viewDidLoad];
|
||
self.view.backgroundColor = [UIColor whiteColor];
|
||
|
||
/// 1:控件初始化
|
||
[self setupUI];
|
||
|
||
/// 2:绑定事件
|
||
// [self bindActions];
|
||
}
|
||
|
||
#pragma mark - 1:控件初始化
|
||
|
||
- (void)setupUI {
|
||
// 添加背景图
|
||
// [self.view addSubview:self.backgroundImageView];
|
||
self.kb_navView.backgroundColor = [UIColor clearColor];
|
||
[self.view insertSubview:self.backgroundImageView belowSubview:self.kb_navView];
|
||
[self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.edges.equalTo(self.view);
|
||
}];
|
||
|
||
// 隐藏默认导航栏标题
|
||
self.kb_titleLabel.hidden = YES;
|
||
|
||
// 添加分类视图到导航栏位置
|
||
[self.kb_navView addSubview:self.categoryView];
|
||
[self.categoryView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.left.equalTo(self.kb_backButton.mas_right).offset(0);
|
||
make.centerY.equalTo(self.kb_backButton);
|
||
make.height.mas_equalTo(44);
|
||
make.width.mas_equalTo(250);
|
||
}];
|
||
|
||
// 添加搜索按钮
|
||
// [self.kb_navView addSubview:self.searchButton];
|
||
// [self.searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
// make.right.equalTo(self.kb_navView).offset(-16);
|
||
// make.centerY.equalTo(self.kb_backButton);
|
||
// make.width.height.mas_equalTo(24);
|
||
// }];
|
||
|
||
// 添加列表容器
|
||
[self.view addSubview:self.listContainerView];
|
||
[self.listContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.top.equalTo(self.kb_navView.mas_bottom);
|
||
make.left.right.bottom.equalTo(self.view);
|
||
}];
|
||
|
||
// 关联 categoryView 和 listContainerView
|
||
self.categoryView.listContainer = self.listContainerView;
|
||
self.listContainerView.backgroundColor = [UIColor clearColor];
|
||
|
||
// 初始状态:默认选中第一个 tab (Thumbs Up),允许左右滑动切换
|
||
// self.listContainerView.scrollView.scrollEnabled = YES;
|
||
self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
|
||
}
|
||
|
||
#pragma mark - 2:绑定事件
|
||
|
||
//- (void)bindActions {
|
||
// [self.searchButton addTarget:self action:@selector(searchButtonTapped) forControlEvents:UIControlEventTouchUpInside];
|
||
//}
|
||
|
||
#pragma mark - Actions
|
||
|
||
- (void)searchButtonTapped {
|
||
// TODO: 跳转搜索页面
|
||
NSLog(@"搜索按钮点击");
|
||
}
|
||
|
||
#pragma mark - JXCategoryViewDelegate
|
||
|
||
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
|
||
NSLog(@"选中分类:%@", self.titles[index]);
|
||
}
|
||
|
||
#pragma mark - JXCategoryListContainerViewDelegate
|
||
|
||
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
|
||
return self.titles.count;
|
||
}
|
||
|
||
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
|
||
if (index == 0) {
|
||
return [[KBAIMessageZanVC alloc] init];
|
||
} else {
|
||
return [[KBAIMessageChatingVC alloc] init];
|
||
}
|
||
}
|
||
|
||
#pragma mark - Lazy Load
|
||
|
||
- (UIImageView *)backgroundImageView {
|
||
if (!_backgroundImageView) {
|
||
_backgroundImageView = [[UIImageView alloc] init];
|
||
_backgroundImageView.image = [UIImage imageNamed:@"message_bg_icon"];
|
||
_backgroundImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||
_backgroundImageView.clipsToBounds = YES;
|
||
}
|
||
return _backgroundImageView;
|
||
}
|
||
|
||
- (NSArray<NSString *> *)titles {
|
||
if (!_titles) {
|
||
_titles = @[KBLocalized(@"Thumbs Up"), KBLocalized(@"Chatting")];
|
||
}
|
||
return _titles;
|
||
}
|
||
|
||
- (JXCategoryTitleView *)categoryView {
|
||
if (!_categoryView) {
|
||
_categoryView = [[JXCategoryTitleView alloc] init];
|
||
_categoryView.backgroundColor = [UIColor clearColor];
|
||
_categoryView.titles = self.titles;
|
||
_categoryView.delegate = self;
|
||
|
||
// 标题样式
|
||
_categoryView.titleFont = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold];
|
||
_categoryView.titleSelectedFont = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold];
|
||
_categoryView.titleColor = [UIColor colorWithHex:0x9F9F9F];
|
||
_categoryView.titleSelectedColor = [UIColor colorWithHex:0x1B1F1A];
|
||
|
||
// 不需要指示器
|
||
_categoryView.indicators = @[];
|
||
|
||
// 间距设置
|
||
_categoryView.cellSpacing = 20;
|
||
_categoryView.contentEdgeInsetLeft = 0;
|
||
_categoryView.contentEdgeInsetRight = 0;
|
||
_categoryView.averageCellSpacingEnabled = NO;
|
||
|
||
// 禁用缩放和渐变
|
||
_categoryView.cellWidthZoomEnabled = NO;
|
||
_categoryView.titleColorGradientEnabled = NO;
|
||
}
|
||
return _categoryView;
|
||
}
|
||
|
||
- (JXCategoryListContainerView *)listContainerView {
|
||
if (!_listContainerView) {
|
||
_listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
|
||
_listContainerView.scrollView.bounces = NO;
|
||
// _listContainerView.scrollView.scrollEnabled = false;
|
||
|
||
// 不延迟触摸事件,让手势能更快响应
|
||
// for (UIGestureRecognizer *gestureRecognizer in _listContainerView.scrollView.gestureRecognizers) {
|
||
// if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
|
||
// gestureRecognizer.delaysTouchesBegan = NO;
|
||
// }
|
||
// }
|
||
}
|
||
return _listContainerView;
|
||
}
|
||
|
||
//- (UIButton *)searchButton {
|
||
// if (!_searchButton) {
|
||
// _searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||
// if (@available(iOS 13.0, *)) {
|
||
// UIImage *searchImage = [UIImage systemImageNamed:@"magnifyingglass"];
|
||
// [_searchButton setImage:searchImage forState:UIControlStateNormal];
|
||
// _searchButton.tintColor = [UIColor colorWithHex:0x1B1F1A];
|
||
// }
|
||
// }
|
||
// return _searchButton;
|
||
//}
|
||
|
||
@end
|