RQMainTabBarViewController.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //
  2. // RQMainTabBarViewController.m
  3. // RQCommon
  4. //
  5. // Created by 张嵘 on 2018/11/21.
  6. // Copyright © 2018 张嵘. All rights reserved.
  7. // 主界面控制器
  8. #import "RQMainTabBarViewController.h"
  9. #import "RQBaseNavigationController.h"
  10. //主页
  11. #import "HomeBaseVC.h"
  12. #import "LearnDrivingVC.h"
  13. #import "NeighbouringVC.h"
  14. #import "FunctionVC.h"
  15. //#import "TimingBaseVC.h"
  16. #import "NeighbouringVC.h"
  17. @interface RQMainTabBarViewController ()
  18. @property (nonatomic, readonly, strong) RQMainTabBarViewModel *viewModel;
  19. @end
  20. @implementation RQMainTabBarViewController
  21. @dynamic viewModel;
  22. #pragma mark - System
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. if (@available(iOS 13.0, *)) {
  26. self.tabBarController.tabBar.tintColor = RQ_MAIN_COLOR;
  27. } else {
  28. self.tabBarController.tabBar.tintColor = [UIColor whiteColor];
  29. }
  30. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  31. self.tabBarController.tabBar.hidden = YES;
  32. }
  33. // 初始化所有的子控制器
  34. [self rq_setupAllChildViewController];
  35. // set delegate
  36. self.tabBarController.delegate = self;
  37. }
  38. #pragma mark - Private Method
  39. - (void)rq_setupAllChildViewController {
  40. NSArray *titlesArray = @[@"考试", @"社区", @"计时", @"报名点", @"个人"];
  41. NSArray *imageNamesArray = @[@"tabbarImg1",
  42. @"tabbarImg2",
  43. @"tabbarImg3",
  44. @"tabbarImg4",
  45. @"tabbarImg5"
  46. ];
  47. NSArray *selectedImageNamesArray = @[@"tabbarImg1",
  48. @"tabbarImg2",
  49. @"tabbarImg3",
  50. @"tabbarImg4",
  51. @"tabbarImg5"
  52. ];
  53. /// 首页-考试
  54. UINavigationController *homePageNavigationController = ({
  55. RQHomePageViewController *homePageViewController = [[RQHomePageViewController alloc] initWithViewModel:self.viewModel.homePageViewModel];
  56. // HomeBaseVC *homePageViewController = [[HomeBaseVC alloc] initWithViewModel:self.viewModel.homePageViewModel];
  57. RQTabBarItemTagType tagType = RQTabBarItemTagTypeHomePage;
  58. /// 配置
  59. [self rq_configViewController:homePageViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];
  60. /// 添加到导航栏的栈底控制器
  61. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  62. } else {
  63. homePageViewController.hidesBottomBarWhenPushed = NO;
  64. }
  65. [[RQBaseNavigationController alloc] initWithRootViewController:homePageViewController];
  66. });
  67. /// 社区
  68. UINavigationController *communityPageNavigationController = ({
  69. LearnDrivingVC *communityPageViewController = [[LearnDrivingVC alloc] initWithViewModel:self.viewModel.communityViewModel];
  70. RQTabBarItemTagType tagType = RQTabBarItemTagTypeCommunity;
  71. /// 配置
  72. [self rq_configViewController:communityPageViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];
  73. /// 添加到导航栏的栈底控制器
  74. [[RQBaseNavigationController alloc] initWithRootViewController:communityPageViewController];
  75. });
  76. /// 报名点
  77. UINavigationController *discoverPageNavigationController = ({
  78. NeighbouringVC *discoverPageViewController = [[NeighbouringVC alloc] initWithViewModel:self.viewModel.discoverViewModel];
  79. discoverPageViewController.isPushed = NO;
  80. RQTabBarItemTagType tagType = RQTabBarItemTagTypeDiscover;
  81. /// 配置
  82. [self rq_configViewController:discoverPageViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];
  83. /// 添加到导航栏的栈底控制器
  84. [[RQBaseNavigationController alloc] initWithRootViewController:discoverPageViewController];
  85. });
  86. /// 我的
  87. UINavigationController *profileNavigationController = ({
  88. // RQProfileViewController *profileViewController = [[RQProfileViewController alloc] initWithViewModel:self.viewModel.profileViewModel];
  89. FunctionVC *profileViewController = [[FunctionVC alloc] initWithViewModel:self.viewModel.profileViewModel];
  90. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  91. } else {
  92. profileViewController.hidesBottomBarWhenPushed = NO;
  93. }
  94. RQTabBarItemTagType tagType = RQTabBarItemTagTypeProfile;
  95. /// 配置
  96. [self rq_configViewController:profileViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];
  97. [[RQBaseNavigationController alloc] initWithRootViewController:profileViewController];
  98. });
  99. /// 添加到tabBarController的子视图
  100. self.tabBarController.viewControllers = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? @[homePageNavigationController] : (RQ_COMMON_MANAGER.LN_SHEQU_OPEN? @[homePageNavigationController, communityPageNavigationController, profileNavigationController] : @[homePageNavigationController, profileNavigationController]);
  101. /// 配置栈底
  102. [RQSharedAppDelegate.navigationControllerStack pushNavigationController:homePageNavigationController];
  103. }
  104. - (void)rq_configViewController:(UIViewController *)viewController imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName title:(NSString *)title itemTag:(RQTabBarItemTagType)tagType {
  105. UIImage *image = [[UIImage imageNamed:imageName] tint:[UIColor grayColor]];
  106. image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  107. viewController.tabBarItem.image = image;
  108. viewController.tabBarItem.tag = tagType;
  109. UIImage *selectedImage = [[UIImage imageNamed:selectedImageName] tint:RQ_MAIN_COLOR];
  110. selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  111. viewController.tabBarItem.selectedImage = selectedImage;
  112. viewController.tabBarItem.title = title;
  113. NSDictionary *normalAttr = @{NSForegroundColorAttributeName:RQ_MAIN_TEXT_COLOR_2,
  114. NSFontAttributeName:RQRegularFont_13};
  115. NSDictionary *selectedAttr = @{NSForegroundColorAttributeName:RQ_MAIN_COLOR,
  116. NSFontAttributeName:RQRegularFont_13};
  117. [viewController.tabBarItem setTitleTextAttributes:normalAttr forState:UIControlStateNormal];
  118. [viewController.tabBarItem setTitleTextAttributes:selectedAttr forState:UIControlStateSelected];
  119. [viewController.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, 0)];
  120. [viewController.tabBarItem setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  121. }
  122. #pragma mark - UITabBarControllerDelegate
  123. - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
  124. if ([viewController.tabBarItem.title isEqualToString:@"个人"] || [viewController.tabBarItem.title isEqualToString:@"计时"]) {
  125. // return RQ_USER_MANAGER.isShouldLogin;
  126. if (!myDelegate.isLogin) {
  127. LoginViewController* vc = [[LoginViewController alloc] init];
  128. vc.modalPresentationStyle = UIModalPresentationFullScreen;
  129. [self presentViewController:vc animated:YES completion:nil];
  130. }
  131. return myDelegate.isLogin;
  132. } else {
  133. return YES;
  134. }
  135. }
  136. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  137. NSLog(@"viewController %@ %zd",viewController,viewController.tabBarItem.tag);
  138. [RQSharedAppDelegate.navigationControllerStack popNavigationController];
  139. [RQSharedAppDelegate.navigationControllerStack pushNavigationController:(UINavigationController *)viewController];
  140. }
  141. @end