123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- //
- // IndexSearchVC.m
- // smartRhino
- //
- // Created by niuzhen on 2020/9/17.
- // Copyright © 2020 tederen. All rights reserved.
- //
- #import "IndexSearchVC.h"
- #import "DrawerView.h"
- #import "TabBarController.h"
- #import "SegmentViewController.h"
- #import "IndexAllVC.h"
- #import "IndexSubVC.h"
- #import "InfoSearchView.h"
- @interface IndexSearchVC ()<InfoSearchViewDelegate>
- @property (nonatomic, strong) InfoSearchView *topNavSearch;
- @property (strong, nonatomic) DrawerView *drawerView;
- @property (strong, nonatomic) SegmentViewController *pageView;
- @property (copy,nonatomic) NSString *searchStr;
- @property (strong, nonatomic) IndexAllVC *allVC;
- @property (strong, nonatomic) IndexSubVC *articeVC;
- @property (strong, nonatomic) IndexSubVC *bookVC;
- @property (strong, nonatomic) IndexSubVC *videoVC;
- @property (strong, nonatomic) IndexSubVC *musicVC;
- @end
- @implementation IndexSearchVC
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self.navigationController.navigationBar setHidden:YES];
- }
- - (DrawerView *)drawerView{
- if(!_drawerView){
- _drawerView = [[DrawerView alloc] init];
- }
- return _drawerView;
- }
- - (InfoSearchView *)topNavSearch {
- if (!_topNavSearch) {
- _topNavSearch = [[InfoSearchView alloc] initWithFrame:CGRectMake(0, (IS_IPHONEX?40:20), kGXScreenWidth, 45) type:InfoSearchViewTypeDefault];
- }
- return _topNavSearch;
- }
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- {
- [self.topNavSearch.searchBar resignFirstResponder];
- }
- - (void)searchButtonAction:(UISearchBar *)searchBar {
- self.searchStr = searchBar.text;
- // 添加历史记录,刷新historyTable
- [self noticeGetData];
- [self.view endEditing:YES];
- }
- - (void)noticeGetData
- {
- if (self.searchStr.length == 0) {
- return;
- }
- switch (self.pageView.selectIndex - 10000) {
- case 0:
- {
- self.allVC.searchText = self.searchStr;
- [self.allVC getData];
- }
- break;
- case 1:
- {
- self.articeVC.searchText = self.searchStr;
- self.articeVC.type = MediaArticeType;
- [self.articeVC getData];
- }
- break;
- case 2:
- {
- self.bookVC.searchText = self.searchStr;
- self.bookVC.type = MediaBookType;
- [self.bookVC getData];
- }
- break;
- case 3:
- {
- self.videoVC.searchText = self.searchStr;
- self.videoVC.type = MediaVideoType;
- [self.videoVC getData];
- }
- break;
- default:
- {
- self.musicVC.searchText = self.searchStr;
- self.musicVC.type = MediaMusicType;
- [self.musicVC getData];
- }
- break;
- }
- }
- // 文本改变回调
- - (void)textDidChange:(NSString *)text {
- self.searchStr = text;
- if (ISEmptyString(text)) {
- // 没有文本显示历史记录cell
- } else {
- // 有文本,就去搜索文章列表,有联想显示联想,没有联想显示历史记录
- }
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:self.topNavSearch];
- [self addNavSearch];
- [self addPageView];
- [self.pageView addObserver:self forKeyPath:@"selectIndex" options:NSKeyValueObservingOptionNew context:nil];
- }
- - (void)dealloc
- {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
- {
- id new = [change objectForKey:@"new"];
- id old = [change objectForKey:@"old"];
- if (new != old) {
- [self noticeGetData];
- }
- }
- - (void)addNavSearch
- {
- WS(weakSelf);
- self.topNavSearch.delegate = self;
- self.topNavSearch.backBlock = ^{
- [weakSelf.navigationController popViewControllerAnimated:YES];
- };
- self.topNavSearch.menuBlock = ^{
- [weakSelf.view endEditing:YES];
- [[UtilsTools getWindow] addSubview:weakSelf.drawerView];
- weakSelf.drawerView.SelectDrawerBlock = ^(NSIndexPath * _Nonnull indexPath) {
- if (![weakSelf.tabBarController isKindOfClass:[TabBarController class]]) {
- [TabBarController sharedTabBarController].tabBar.hidden = NO;
- [weakSelf.tabBarController.navigationController popViewControllerAnimated:NO];
- }
- if ([weakSelf.navigationController.viewControllers count] > 1) {
- [weakSelf.navigationController popToRootViewControllerAnimated:NO];
- }
- switch (indexPath.section) {
- case 0:
- {
- [[TabBarController sharedTabBarController] setSelectedIndex:indexPath.row];
- }
- break;
- case 1:
- {
- switch (indexPath.row) {
- case 0:
- {
- [[TabBarController sharedTabBarController] setSelectedIndex:2];
- }
- break;
- case 1:
- {
- [[TabBarController sharedTabBarController] setSelectedIndex:2];
- }
- break;
- default:
- {
- [[TabBarController sharedTabBarController] setSelectedIndex:3];
- }
- break;
- }
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [[NSNotificationCenter defaultCenter] postNotificationName:DRAWERPUSHVC object:nil userInfo:@{VCINDEX:@(indexPath.row)}];
- });
- }
- break;
- default:
- {
- [[TabBarController sharedTabBarController] setSelectedIndex:3];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [[NSNotificationCenter defaultCenter] postNotificationName:DRAWERPUSHVC object:nil userInfo:@{VCINDEX:@(4 + indexPath.row)}];
- });
- }
- break;
- }
- };
- weakSelf.drawerView.frame = CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT);// - kNavigationHeight
- };
- }
- - (void)addPageView
- {
- self.pageView = [[SegmentViewController alloc] init];
- NSArray * titleArray = @[@"全部",@"文章",@"书籍",@"视频",@"音频"];
- self.pageView.titleArray = titleArray;
- NSMutableArray *controlArray = [[NSMutableArray alloc]init];
-
- self.allVC = [[IndexAllVC alloc]init];
- [controlArray addObject:self.allVC];
- self.articeVC = [[IndexSubVC alloc]init];
- [controlArray addObject:self.articeVC];
- self.bookVC = [[IndexSubVC alloc]init];
- [controlArray addObject:self.bookVC];
-
- self.videoVC = [[IndexSubVC alloc]init];
- [controlArray addObject:self.videoVC];
-
- self.musicVC = [[IndexSubVC alloc]init];
- [controlArray addObject:self.musicVC];
- self.pageView.subViewControllers = controlArray;
- self.pageView.buttonWidth = self.view.frame.size.width / titleArray.count;
- self.pageView.buttonHeight = 34.f;
- self.pageView.bottomCount = titleArray.count;
- [self.pageView initSegment:0];
- [self.pageView addParentController:self];
- [self.pageView.view setFrame:CGRectMake(0, CGRectGetMaxY(self.topNavSearch.frame), SCREEN_WIDTH, SCREEN_HEIGHT - CGRectGetMaxY(self.topNavSearch.frame))];
- }
- @end
|