Files
yinmeng-ios/xplan-ios/Main/Home/View/XPRoomSearchContainerViewController.m
chenguilong 11ff4a7986 主播卡片
2022-08-02 14:04:26 +08:00

188 lines
5.7 KiB
Objective-C

//
// XPRoomSearchContaierViewController.m
// xplan-ios
//
// Created by 冯硕 on 2021/12/2.
//
#import "XPRoomSearchContainerViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <JXCategoryView/JXCategoryView.h>
#import <JXCategoryView/JXCategoryListContainerView.h>
///Tool
#import "XPMacro.h"
#import "ThemeColor.h"
#import "XPHomeSearchNavView.h"
///View
#import "XPHomeSearchViewController.h"
UIKIT_EXTERN NSString *kFromSearchToHomeViewKey;
UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
@interface XPRoomSearchContainerViewController ()<JXCategoryViewDelegate, JXCategoryListContainerViewDelegate, XPHomeSearchNavViewDelegate,UITextFieldDelegate>
///分页标题
@property (nonatomic, strong) NSArray<NSString *> *titles;
///分页控件
@property (nonatomic, strong) JXCategoryTitleView *titleView;
///分页lineView
@property (nonatomic, strong) JXCategoryListContainerView *contentView;
///搜索
@property (nonatomic,strong) XPHomeSearchNavView *searchView;
///房间
@property (nonatomic,strong) XPHomeSearchViewController *roomVC;
///用户
@property (nonatomic,strong) XPHomeSearchViewController *userVC;
@end
@implementation XPRoomSearchContainerViewController
- (BOOL)isHiddenNavBar {
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initSubViews];
[self initSubViewConstraints];
self.modalPresentationStyle = UIModalPresentationOverFullScreen;
}
#pragma mark - Private Method
- (void)initSubViews {
[self.view addSubview:self.searchView];
[self.view addSubview:self.titleView];
[self.view addSubview:self.contentView];
}
- (void)initSubViewConstraints {
[self.searchView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.mas_equalTo(self.view);
make.height.mas_equalTo(kNavigationHeight);
}];
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.view);
make.top.mas_equalTo(self.searchView.mas_bottom).offset(10);
make.height.mas_equalTo(50);
}];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.titleView.mas_bottom).offset(10);
make.left.right.bottom.mas_equalTo(self.view);
}];
}
- (void)searchVCLoadData:(NSString *)text {
[self.roomVC searchText:text];
[self.userVC searchText:text];
}
#pragma mark - JXCategoryViewDelegate
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
return self.titles.count;
}
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
if (index == 0) {
return self.roomVC;
}
return self.userVC;
}
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField.text.length > 0) {
[textField resignFirstResponder];
[self searchVCLoadData:textField.text];
} else {
[self showErrorToast:@"请输入需要搜索的内容"];
}
return YES;
}
#pragma mark -XPHomeSearchNavViewDelegate
- (void)xPHomeSearchNavView:(XPHomeSearchNavView *)view didClickSearch:(UIButton *)sender {
if (view.searchTextField.text.length > 0) {
[view.searchTextField resignFirstResponder];
[self searchVCLoadData:view.searchTextField.text];
} else {
[self showErrorToast:@"请输入需要搜索的内容"];
}
}
- (void)xPHomeSearchNavView:(XPHomeSearchNavView *)view didClickBack:(UIButton *)sender {
[view.searchTextField resignFirstResponder];
BOOL result = [[NSUserDefaults standardUserDefaults] boolForKey:kFromSearchToHomeViewKey];
if (!result) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kFromSearchToHomeViewKey];
[[NSUserDefaults standardUserDefaults] synchronize];
[[NSNotificationCenter defaultCenter] postNotificationName:kTabShowAnchorCardKey object:nil];
}
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - Getters And Setters
- (JXCategoryTitleView *)titleView {
if (!_titleView) {
_titleView = [[JXCategoryTitleView alloc] init];
_titleView.delegate = self;
_titleView.titles = self.titles;
_titleView.titleColor = [ThemeColor secondTextColor];
_titleView.titleSelectedColor = [ThemeColor mainTextColor];
_titleView.titleFont = [UIFont fontWithName:@"PingFang-SC-Medium" size:16];
_titleView.titleSelectedFont = [UIFont fontWithName:@"PingFang-SC-Medium" size:16];
_titleView.titleLabelAnchorPointStyle = JXCategoryTitleLabelAnchorPointStyleCenter;
_titleView.contentScrollViewClickTransitionAnimationEnabled = NO;
_titleView.defaultSelectedIndex = 0;
_titleView.listContainer = self.contentView;
JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
lineView.indicatorColor = [ThemeColor appMainColor];
lineView.indicatorWidth = 8.f;
lineView.indicatorHeight = 4.f;
lineView.indicatorCornerRadius = 2.f;
_titleView.indicators = @[lineView];
}
return _titleView;
}
- (JXCategoryListContainerView *)contentView {
if (!_contentView) {
_contentView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
_contentView.defaultSelectedIndex = 0;
}
return _contentView;
}
- (NSArray<NSString *> *)titles {
return @[@"房间", @"用户"];
}
- (XPHomeSearchNavView *)searchView {
if (!_searchView) {
_searchView = [[XPHomeSearchNavView alloc] init];
_searchView.delegate = self;
_searchView.searchTextField.delegate = self;
}
return _searchView;
}
- (XPHomeSearchViewController *)roomVC {
if (!_roomVC) {
_roomVC = [[XPHomeSearchViewController alloc] init];
_roomVC.type = SearchType_Room;
}
return _roomVC;
}
- (XPHomeSearchViewController *)userVC {
if (!_userVC) {
_userVC = [[XPHomeSearchViewController alloc] init];
_userVC.type = SearchType_Users;
}
return _userVC;
}
@end