// // ASBaseViewController.m // Asteria // // Created by iOS on 2023/4/24. // #import "ASBaseViewController.h" #import "AppDelegate.h" @interface ASBaseViewController () @property (nonatomic, strong) UIImageView *leftImgV; @property (nonatomic, strong) UITextField *searchTf; @property (nonatomic, strong) UIButton *tfBt; @property (nonatomic, copy) btnClickBlock tapSearchBlock; @property (nonatomic, strong) UIButton *backBt; @property (nonatomic, strong) UIButton *searchNavBt; @property (nonatomic, copy) btnClickBlock nav_searchBlock; @property (nonatomic, strong) UIView *emptyV; @property (nonatomic, strong) UILabel *emptylb; @end @implementation ASBaseViewController - (void)toHomeVc { if (self.navigationController != nil) { [self.navigationController popToRootViewControllerAnimated:false]; } QMUITabBarViewController *tabVC = (QMUITabBarViewController *)((AppDelegate *)UIApplication.sharedApplication.delegate).window.rootViewController; tabVC.selectedIndex = 0; } - (void)popAndToLogin { QMUITabBarViewController *tabVC = (QMUITabBarViewController *)((AppDelegate *)UIApplication.sharedApplication.delegate).window.rootViewController; tabVC.selectedIndex = 0; UITabBar *tabbar = tabVC.tabBar; if (tabbar.items.count > 2) { UITabBarItem *temp = tabbar.items[2]; temp.qmui_badgeInteger = 0; } UIViewController *loginC = [[CTMediator sharedInstance] Login_LoginC:@{}]; QMUINavigationController *uikitNavController = [[QMUINavigationController alloc] initWithRootViewController:loginC]; uikitNavController.navigationBar.hidden = YES; uikitNavController.modalPresentationStyle = UIModalPresentationFullScreen; [tabVC presentViewController:uikitNavController animated:YES completion:nil]; } - (void)toLoginVC { UIViewController *loginC = [[CTMediator sharedInstance] Login_LoginC:@{}]; QMUINavigationController *uikitNavController = [[QMUINavigationController alloc] initWithRootViewController:loginC]; uikitNavController.navigationBar.hidden = YES; uikitNavController.modalPresentationStyle = UIModalPresentationFullScreen; [self presentViewController:uikitNavController animated:YES completion:nil]; } - (void)setTitleStr:(NSString *)titleStr { _titleStr = titleStr; self.nav_titleLB.text = _titleStr; } - (void)hiddenEmpty { self.emptyV.hidden = true; } - (void)setEmptyTip:(NSString *)tipStr { self.emptylb.text = tipStr; } - (void)showEmptyV:(UIView *)v { if (self.emptyV.superview == v) { self.emptyV.hidden = false; [self.emptyV.superview bringSubviewToFront:self.emptyV]; return; } if (v == nil) { [self.view addSubview:self.emptyV]; [self.emptyV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.customNavBar.mas_bottom); make.leading.trailing.bottom.equalTo(self.view); }]; } else { [v addSubview:self.emptyV]; [self.emptyV mas_remakeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(v); make.width.height.equalTo(v); }]; } self.emptyV.hidden = false; [self.emptyV.superview bringSubviewToFront:self.emptyV]; dispatch_async(dispatch_get_main_queue(), ^{ [UIView viewAddHorColorBg:self.emptyV colorArr:@[ (id)_E0FFF5.CGColor, (id)Col_FFF.CGColor ] startP:CGPointMake(0.5, 0.25) endP:CGPointMake(0.5, 1)]; [self.emptyV bringSubviewToFront:self.emptylb]; }); } - (void)viewDidLoad { [super viewDidLoad]; [self addBaseNav]; self.navigationController.navigationBar.hidden = true; self.customNavBar.backgroundColor = Col_FFF; self.view.backgroundColor = _F8F8F8; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.tabBarController.tabBar.hidden = self.navigationController.viewControllers.count > 1; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillAppear:animated]; } - (void)setNavRightSearch:(btnClickBlock)nav_searchAction { self.nav_searchBlock = nav_searchAction; [self.customNavBar addSubview:self.searchNavBt]; [self.searchNavBt mas_makeConstraints:^(MASConstraintMaker *make) { make.width.height.equalTo(@44); make.trailing.equalTo(self.customNavBar).offset(-10); make.centerY.equalTo(self.customNavBar); }]; } - (void)ucHomeStyle:(btnClickBlock)tapSearch { self.tapSearchBlock = tapSearch; [self.customNavBar addSubview:self.leftImgV]; [self.customNavBar addSubview:self.searchTf]; [self.customNavBar addSubview:self.tfBt]; [self.leftImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.customNavBar).offset(20); make.width.equalTo(@140); make.height.equalTo(@43.5); make.centerY.equalTo(self.customNavBar); }]; [self.searchTf mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.leftImgV.mas_trailing).offset(20); make.height.equalTo(@36); make.centerY.equalTo(self.leftImgV); make.trailing.equalTo(self.customNavBar).offset(-10); }]; [self.tfBt mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.searchTf); }]; } - (void)addBaseNav { [self.view addSubview:self.statusBgV]; [self.view addSubview:self.customNavBar]; [self.customNavBar addSubview:self.nav_bottomLineV]; self.statusBgV.frame = CGRectMake(0, 0, KScreenWidth, kStatusBarH); self.customNavBar.frame = CGRectMake(0, kStatusBarH, KScreenWidth, kCustomNavBarH); self.nav_bottomLineV.frame = CGRectMake(0, kCustomNavBarH-1, KScreenWidth, 1); [self.customNavBar addSubview:self.backBt]; [self.customNavBar addSubview:self.nav_titleLB]; [self.backBt mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.customNavBar).offset(10); make.centerY.equalTo(self.customNavBar); make.width.height.equalTo(@44); }]; [self.nav_titleLB mas_makeConstraints:^(MASConstraintMaker *make) { make.center.equalTo(self.customNavBar); make.width.equalTo(self.customNavBar).offset(-120); make.height.equalTo(@40); }]; self.backBt.hidden = true; if (self.navigationController.viewControllers.count > 1) { self.backBt.hidden = false; } [self.emptyV addSubview:self.emptylb]; [self.emptylb mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.emptyV).offset(30); make.trailing.equalTo(self.emptyV).offset(-30); make.centerY.equalTo(self.emptyV).offset(-30); make.top.greaterThanOrEqualTo(self.emptyV).offset(20); }]; } // MARK: - actions - (void)searchBtAction { UIViewController *vc = [CTMediator.sharedInstance getSearchVc:@{}]; [self presentViewController:vc animated:true completion:nil]; if (self.tapSearchBlock) { self.tapSearchBlock(); } } // MARK: - subVs - (UIView *)emptyV { if (!_emptyV) { UIView *v = [UIView baseV]; v.backgroundColor = Col_FFF; v.hidden = true; _emptyV = v; } return _emptyV; } - (UILabel *)emptylb { if (!_emptylb) { UILabel *lb = [UILabel baseLb]; lb.font = [UIFont fontWithName:Rob_Medium size:72]; lb.textAlignment = NSTextAlignmentCenter; lb.numberOfLines = 0; lb.text = @"No Data"; lb.textColor = _043632; _emptylb = lb; } return _emptylb; } - (UIView *)statusBgV { if (!_statusBgV) { UIView *v = [UIView baseV]; v.backgroundColor = _32CFB0; _statusBgV = v; } return _statusBgV; } - (UIView *)customNavBar { if (!_customNavBar) { UIView *v = [UIView baseV]; v.backgroundColor = _32CFB0; _customNavBar = v; } return _customNavBar; } - (UIView *)nav_bottomLineV { if (!_nav_bottomLineV) { UIView *v = [UIView baseV]; v.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.05]; _nav_bottomLineV = v; } return _nav_bottomLineV; } - (UIImageView *)leftImgV { if (!_leftImgV) { UIImageView *v = [UIImageView baseImgV]; v.image = [UIImage imageNamed:@"nav_icon"]; _leftImgV = v; } return _leftImgV; } - (UITextField *)searchTf { if (!_searchTf) { UITextField *tf = [[UITextField alloc] init]; tf.borderStyle = UITextBorderStyleNone; UIView *leftV = [[UIView alloc] init]; leftV.backgroundColor = UIColor.clearColor; UIImageView *imgV = [UIImageView baseImgV]; imgV.backgroundColor = UIColor.clearColor; imgV.image = [UIImage imageNamed:@"nav_search"]; leftV.frame = CGRectMake(0, 0, 44, 36); imgV.frame = CGRectMake(10, 6, 24, 24); [leftV addSubview:imgV]; tf.leftView = leftV; tf.leftViewMode = UITextFieldViewModeAlways; tf.backgroundColor = _F5F5F5; tf.layer.cornerRadius = 5; tf.layer.masksToBounds = true; _searchTf = tf; } return _searchTf; } - (UIButton *)tfBt { if (!_tfBt) { UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom]; [bt addTarget:self action:@selector(searchBtAction) forControlEvents:UIControlEventTouchUpInside]; _tfBt = bt; } return _tfBt; } - (UIButton *)backBt { if (!_backBt) { UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom]; [bt setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal]; [bt addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside]; _backBt = bt; } return _backBt; } - (UILabel *)nav_titleLB { if (!_nav_titleLB) { UILabel *lb = [[UILabel alloc] init]; lb.font = [UIFont fontWithName:Rob_Regular size:20]; lb.textAlignment = NSTextAlignmentCenter; lb.textColor = Col_000; _nav_titleLB = lb; } return _nav_titleLB; } - (void)backAction { [self.navigationController popViewControllerAnimated:true]; } - (UIButton *)searchNavBt { if (!_searchNavBt) { UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom]; [bt setImage:[UIImage imageNamed:@"nav_search"] forState:UIControlStateNormal]; [bt addTarget:self action:@selector(search_navAction) forControlEvents:UIControlEventTouchUpInside]; _searchNavBt = bt; } return _searchNavBt; } // MARK: - actions - (void)search_navAction { UIViewController *vc = [CTMediator.sharedInstance getSearchVc:@{}]; [self presentViewController:vc animated:true completion:nil]; if (self.nav_searchBlock) { self.nav_searchBlock(); } } @end