RQMainTabBarViewController.m 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. @interface RQMainTabBarViewController ()
  11. @property (nonatomic, readonly, strong) RQMainTabBarViewModel *viewModel;
  12. @end
  13. @implementation RQMainTabBarViewController
  14. @dynamic viewModel;
  15. #pragma mark - System
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. // 初始化所有的子控制器
  19. [self rq_setupAllChildViewController];
  20. // set delegate
  21. self.tabBarController.delegate = self;
  22. }
  23. #pragma mark - Private Method
  24. - (void)rq_setupAllChildViewController {
  25. NSArray *titlesArray = @[@"考试", @"社区", @"计时",@"真人讲解", @"我的"];
  26. NSArray *imageNamesArray = @[@"考试灰",
  27. @"tabbarImg2",
  28. @"计时灰",
  29. @"真人讲解灰",
  30. @"我的灰"
  31. ];
  32. NSArray *selectedImageNamesArray = @[@"考试蓝",
  33. @"tabbarImg2",
  34. @"计时蓝",
  35. @"真人讲解蓝",
  36. @"我的蓝"
  37. ];
  38. /// 首页-考试
  39. RQBaseNavigationController *homePageNavigationController = ({
  40. RQHomePageViewController *homePageViewController = [[RQHomePageViewController alloc] initWithViewModel:self.viewModel.homePageViewModel];
  41. RQTabBarItemTagType tagType = RQTabBarItemTagTypeHomePage;
  42. /// 配置
  43. [self rq_configViewController:homePageViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];
  44. /// 添加到导航栏的栈底控制器
  45. homePageViewController.hidesBottomBarWhenPushed = NO;
  46. [[RQBaseNavigationController alloc] initWithRootViewController:homePageViewController];
  47. });
  48. /// 计时
  49. RQBaseNavigationController *timePageNavigationController = ({
  50. // TimingBaseVC *timePageViewController = [[TimingBaseVC alloc] initWithViewModel:self.viewModel.timeViewModel];
  51. RQTimeViewController *timePageViewController = [[RQTimeViewController alloc] initWithViewModel:self.viewModel.timeViewModel];
  52. RQTabBarItemTagType tagType = RQTabBarItemTagTypeTime;
  53. /// 配置
  54. [self rq_configViewController:timePageViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];
  55. /// 添加到导航栏的栈底控制器
  56. timePageViewController.hidesBottomBarWhenPushed = NO;
  57. [[RQBaseNavigationController alloc] initWithRootViewController:timePageViewController];
  58. });
  59. ///真人讲解
  60. RQBaseNavigationController *livideoNavigationController = ({
  61. RQTimeViewController *timePageViewController = [[RQTimeViewController alloc] initWithViewModel:self.viewModel.timeViewModel];
  62. RQTabBarItemTagType tagType = RQTabBarItemTagTypeLi;
  63. /// 配置
  64. [self rq_configViewController:timePageViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];
  65. /// 添加到导航栏的栈底控制器
  66. timePageViewController.hidesBottomBarWhenPushed = NO;
  67. [[RQBaseNavigationController alloc] initWithRootViewController:timePageViewController];
  68. });
  69. /// 我的
  70. RQBaseNavigationController *profileNavigationController = ({
  71. //#if DEBUG
  72. RQProfileViewController *profileViewController = [[RQProfileViewController alloc] initWithViewModel:self.viewModel.profileViewModel];
  73. //#else
  74. // FunctionVC *profileViewController = [[FunctionVC alloc] initWithViewModel:self.viewModel.profileViewModel];
  75. //#endif
  76. RQTabBarItemTagType tagType = RQTabBarItemTagTypeProfile;
  77. /// 配置
  78. [self rq_configViewController:profileViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];
  79. profileViewController.hidesBottomBarWhenPushed = NO;
  80. [[RQBaseNavigationController alloc] initWithRootViewController:profileViewController];
  81. });
  82. /// 添加到tabBarController的子视图
  83. // self.tabBarController.viewControllers = @[homePageNavigationController, profileNavigationController];
  84. self.tabBarController.viewControllers = @[homePageNavigationController, timePageNavigationController,livideoNavigationController, profileNavigationController];//开启计时tab
  85. // if(RQ_USER_MANAGER.currentUser.stuNum){
  86. // NSLog(@"%@",RQ_USER_MANAGER.currentUser.stuNum);
  87. // if ((RQ_USER_MANAGER.isLogin&&![RQ_USER_MANAGER.currentUser.stuNum isEqualToString:@""])||
  88. // [RQ_USER_MANAGER.currentUser.loginCode isEqualToString:@"350881199205290949"]) {//已经,登录并且stunum不为空
  89. // self.tabBarController.viewControllers = @[homePageNavigationController, timePageNavigationController, profileNavigationController];//开启计时tab
  90. // }
  91. // }
  92. /// 配置栈底
  93. [RQSharedAppDelegate.navigationControllerStack pushNavigationController:homePageNavigationController];
  94. }
  95. - (void)rq_configViewController:(UIViewController *)viewController imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName title:(NSString *)title itemTag:(RQTabBarItemTagType)tagType {
  96. UIImage *image = [[UIImage imageNamed:imageName] tint:[UIColor grayColor]];
  97. image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  98. viewController.tabBarItem.image = image;
  99. viewController.tabBarItem.tag = tagType;
  100. UIImage *selectedImage = [[UIImage imageNamed:selectedImageName] tint:RQ_MAIN_COLOR];
  101. selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  102. viewController.tabBarItem.selectedImage = selectedImage;
  103. viewController.tabBarItem.title = title;
  104. NSDictionary *normalAttr = @{NSForegroundColorAttributeName:RQ_MAIN_TEXT_COLOR_2,
  105. NSFontAttributeName:RQRegularFont_15};
  106. NSDictionary *selectedAttr = @{NSForegroundColorAttributeName:RQ_MAIN_COLOR,
  107. NSFontAttributeName:RQRegularFont_15};
  108. [viewController.tabBarItem setTitleTextAttributes:normalAttr forState:UIControlStateNormal];
  109. [viewController.tabBarItem setTitleTextAttributes:selectedAttr forState:UIControlStateSelected];
  110. [viewController.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, 0)];
  111. [viewController.tabBarItem setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  112. }
  113. #pragma mark - UITabBarControllerDelegate
  114. - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
  115. if ([viewController.tabBarItem.title isEqualToString:@"我的"] || [viewController.tabBarItem.title isEqualToString:@"计时"]) {
  116. return RQ_USER_MANAGER.isShouldLogin;
  117. } else {
  118. return YES;
  119. }
  120. }
  121. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  122. NSLog(@"viewController %@ %zd",viewController,viewController.tabBarItem.tag);
  123. [RQSharedAppDelegate.navigationControllerStack popNavigationController];
  124. [RQSharedAppDelegate.navigationControllerStack pushNavigationController:(UINavigationController *)viewController];
  125. if ([viewController.tabBarItem.title isEqualToString:@"计时"] && [RQ_USER_MANAGER isQzVideo] && !RQ_COMMON_MANAGER.isQzLook) {
  126. RQNewFeatureViewModel *newFeatureViewModel = [[RQNewFeatureViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{RQViewCommonValueKey : @"quanzhou"}];
  127. [RQ_APPDELEGATE.services presentViewModel:newFeatureViewModel animated:YES completion:^{
  128. }];
  129. }
  130. }
  131. @end