123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- //
- // BaseViewController.m
- // TheoryNetwork
- //
- // Created by tederen on 2019/9/20.
- // Copyright © 2019 tederen. All rights reserved.
- //
- #import "BaseViewController.h"
- #import "DrawerView.h"
- #import "TabBarController.h"
- @interface BaseViewController ()
- @property (strong,nonatomic) DrawerView *drawerView;
- @end
- @implementation BaseViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor whiteColor];
- // Do any additional setup after loading the view.
- self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"首页-书籍详情-返回"] style:0 target:self action:@selector(back)];
- if (kBooliPhoneX) {
- self.customNavigationHeight.constant = 88.f;
- }else {
- self.customNavigationHeight.constant = 64.f;
- }
- }
- -(void)back{
- if (self.navigationController.viewControllers.count > 1) {
- [self.navigationController popViewControllerAnimated:YES];
- }else{
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- }
- - (BOOL)hidesBottomBarWhenPushed
- {
- return YES;
- }
- -(IBAction)backAction:(id)sender{
- if(self.drawerView){
- [self.drawerView removeFromSuperview];
- }
- if (self.navigationController.viewControllers.count > 1) {
- [self.navigationController popViewControllerAnimated:YES];
- }else{
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- }
- -(IBAction)menuAction:(id)sender{
- [self.view endEditing:YES];
- [[UtilsTools getWindow] addSubview:self.drawerView];
- WS(weakSelf);
- self.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];
- }
- if (indexPath.section == 0) {
- [[TabBarController sharedTabBarController] setSelectedIndex:indexPath.row];
- }else{
- ///@"站内信", @"通知", @"收藏",@"笔记", @"设置"
- 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)}];
- });
- }
- };
- self.drawerView.frame = CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT);// - kNavigationHeight
- }
- //- (BOOL)prefersStatusBarHidden{
- // return YES;
- //}
- //给外部提供一个可调用打开菜单View的方法
- -(void)openMenuViewWithDidMenuBtn{
- [self menuAction:nil];
- }
- //给外部提供一个可调用返回上一级的方法
- -(void)backToUpVcWithDidBackBtn{
- [self backAction:nil];
- }
-
- -(DrawerView *)drawerView{
- if(!_drawerView){
- _drawerView = [[DrawerView alloc] init];
- }
- return _drawerView;
- }
- - (UILabel *)noDataMessageLbl {
- if (!_noDataMessageLbl) {
- _noDataMessageLbl = [[UILabel alloc] init];
- _noDataMessageLbl.font = [UIFont systemFontOfSize:15];
- _noDataMessageLbl.textColor = [UIColor colorWithHexString:@"BBBBBB"];
- _noDataMessageLbl.textAlignment = NSTextAlignmentCenter;
- _noDataMessageLbl.hidden = YES;
- }
- return _noDataMessageLbl;
- }
- - (void)addNoDataMessageToViewCenter:(UIView *)contentView message:(NSString *)message {
- [self.noDataMessageLbl removeFromSuperview];
- self.noDataMessageLbl.text = message;
- [contentView addSubview:self.noDataMessageLbl];
- [self.noDataMessageLbl mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(contentView.mas_centerY);
- make.centerX.equalTo(contentView.mas_centerX);
- make.height.mas_equalTo(30);
- }];
- }
- - (void)changeMessageStatusWithNumber:(NSInteger)number {
- if (number > 0) {
- self.noDataMessageLbl.hidden = YES;
- }else {
- self.noDataMessageLbl.hidden = NO;
- }
- }
- @end
|