BaseViewController.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // BaseViewController.m
  3. // TheoryNetwork
  4. //
  5. // Created by tederen on 2019/9/20.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "BaseViewController.h"
  9. #import "DrawerView.h"
  10. #import "TabBarController.h"
  11. @interface BaseViewController ()
  12. @property (strong,nonatomic) DrawerView *drawerView;
  13. @end
  14. @implementation BaseViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. self.view.backgroundColor = [UIColor whiteColor];
  18. // Do any additional setup after loading the view.
  19. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"首页-书籍详情-返回"] style:0 target:self action:@selector(back)];
  20. if (kBooliPhoneX) {
  21. self.customNavigationHeight.constant = 88.f;
  22. }else {
  23. self.customNavigationHeight.constant = 64.f;
  24. }
  25. }
  26. -(void)back{
  27. if (self.navigationController.viewControllers.count > 1) {
  28. [self.navigationController popViewControllerAnimated:YES];
  29. }else{
  30. [self dismissViewControllerAnimated:YES completion:nil];
  31. }
  32. }
  33. - (BOOL)hidesBottomBarWhenPushed
  34. {
  35. return YES;
  36. }
  37. -(IBAction)backAction:(id)sender{
  38. if(self.drawerView){
  39. [self.drawerView removeFromSuperview];
  40. }
  41. if (self.navigationController.viewControllers.count > 1) {
  42. [self.navigationController popViewControllerAnimated:YES];
  43. }else{
  44. [self dismissViewControllerAnimated:YES completion:nil];
  45. }
  46. }
  47. -(IBAction)menuAction:(id)sender{
  48. [self.view endEditing:YES];
  49. [[UtilsTools getWindow] addSubview:self.drawerView];
  50. WS(weakSelf);
  51. self.drawerView.SelectDrawerBlock = ^(NSIndexPath * _Nonnull indexPath) {
  52. if (![weakSelf.tabBarController isKindOfClass:[TabBarController class]]) {
  53. [TabBarController sharedTabBarController].tabBar.hidden = NO;
  54. [weakSelf.tabBarController.navigationController popViewControllerAnimated:NO];
  55. }
  56. if ([weakSelf.navigationController.viewControllers count] > 1) {
  57. [weakSelf.navigationController popToRootViewControllerAnimated:NO];
  58. }
  59. if (indexPath.section == 0) {
  60. [[TabBarController sharedTabBarController] setSelectedIndex:indexPath.row];
  61. }else{
  62. ///@"站内信", @"通知", @"收藏",@"笔记", @"设置"
  63. switch (indexPath.row) {
  64. case 0:
  65. {
  66. [[TabBarController sharedTabBarController] setSelectedIndex:2];
  67. }
  68. break;
  69. case 1:
  70. {
  71. [[TabBarController sharedTabBarController] setSelectedIndex:2];
  72. }
  73. break;
  74. default:
  75. {
  76. [[TabBarController sharedTabBarController] setSelectedIndex:3];
  77. }
  78. break;
  79. }
  80. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  81. [[NSNotificationCenter defaultCenter] postNotificationName:DRAWERPUSHVC object:nil userInfo:@{VCINDEX:@(indexPath.row)}];
  82. });
  83. }
  84. };
  85. self.drawerView.frame = CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT);// - kNavigationHeight
  86. }
  87. //- (BOOL)prefersStatusBarHidden{
  88. // return YES;
  89. //}
  90. //给外部提供一个可调用打开菜单View的方法
  91. -(void)openMenuViewWithDidMenuBtn{
  92. [self menuAction:nil];
  93. }
  94. //给外部提供一个可调用返回上一级的方法
  95. -(void)backToUpVcWithDidBackBtn{
  96. [self backAction:nil];
  97. }
  98. -(DrawerView *)drawerView{
  99. if(!_drawerView){
  100. _drawerView = [[DrawerView alloc] init];
  101. }
  102. return _drawerView;
  103. }
  104. - (UILabel *)noDataMessageLbl {
  105. if (!_noDataMessageLbl) {
  106. _noDataMessageLbl = [[UILabel alloc] init];
  107. _noDataMessageLbl.font = [UIFont systemFontOfSize:15];
  108. _noDataMessageLbl.textColor = [UIColor colorWithHexString:@"BBBBBB"];
  109. _noDataMessageLbl.textAlignment = NSTextAlignmentCenter;
  110. _noDataMessageLbl.hidden = YES;
  111. }
  112. return _noDataMessageLbl;
  113. }
  114. - (void)addNoDataMessageToViewCenter:(UIView *)contentView message:(NSString *)message {
  115. [self.noDataMessageLbl removeFromSuperview];
  116. self.noDataMessageLbl.text = message;
  117. [contentView addSubview:self.noDataMessageLbl];
  118. [self.noDataMessageLbl mas_makeConstraints:^(MASConstraintMaker *make) {
  119. make.centerY.equalTo(contentView.mas_centerY);
  120. make.centerX.equalTo(contentView.mas_centerX);
  121. make.height.mas_equalTo(30);
  122. }];
  123. }
  124. - (void)changeMessageStatusWithNumber:(NSInteger)number {
  125. if (number > 0) {
  126. self.noDataMessageLbl.hidden = YES;
  127. }else {
  128. self.noDataMessageLbl.hidden = NO;
  129. }
  130. }
  131. @end