123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- //
- // RQMainTabBarViewController.m
- // RQCommon
- //
- // Created by 张嵘 on 2018/11/21.
- // Copyright © 2018 张嵘. All rights reserved.
- // 主界面控制器
- #import "RQMainTabBarViewController.h"
- #import "RQBaseNavigationController.h"
- //主页
- #import "HomeBaseVC.h"
- #import "LearnDrivingVC.h"
- #import "NeighbouringVC.h"
- #import "FunctionVC.h"
- //#import "TimingBaseVC.h"
- #import "NeighbouringVC.h"
- @interface RQMainTabBarViewController ()
- @property (nonatomic, readonly, strong) RQMainTabBarViewModel *viewModel;
- @end
- @implementation RQMainTabBarViewController
- @dynamic viewModel;
- #pragma mark - System
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- if (@available(iOS 13.0, *)) {
- self.tabBarController.tabBar.tintColor = RQ_MAIN_COLOR;
- } else {
- self.tabBarController.tabBar.tintColor = [UIColor whiteColor];
- }
-
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- self.tabBarController.tabBar.hidden = YES;
- }
- // 初始化所有的子控制器
- [self rq_setupAllChildViewController];
-
- // set delegate
- self.tabBarController.delegate = self;
-
- }
- #pragma mark - Private Method
- - (void)rq_setupAllChildViewController {
- NSArray *titlesArray = @[@"考试", @"社区", @"计时", @"报名点", @"个人"];
- NSArray *imageNamesArray = @[@"tabbarImg1",
- @"tabbarImg2",
- @"tabbarImg3",
- @"tabbarImg4",
- @"tabbarImg5"
- ];
- NSArray *selectedImageNamesArray = @[@"tabbarImg1",
- @"tabbarImg2",
- @"tabbarImg3",
- @"tabbarImg4",
- @"tabbarImg5"
- ];
-
- /// 首页-考试
- UINavigationController *homePageNavigationController = ({
- RQHomePageViewController *homePageViewController = [[RQHomePageViewController alloc] initWithViewModel:self.viewModel.homePageViewModel];
- // HomeBaseVC *homePageViewController = [[HomeBaseVC alloc] initWithViewModel:self.viewModel.homePageViewModel];
-
- RQTabBarItemTagType tagType = RQTabBarItemTagTypeHomePage;
- /// 配置
- [self rq_configViewController:homePageViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];
- /// 添加到导航栏的栈底控制器
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
-
- } else {
- homePageViewController.hidesBottomBarWhenPushed = NO;
- }
- [[RQBaseNavigationController alloc] initWithRootViewController:homePageViewController];
- });
-
- /// 社区
- UINavigationController *communityPageNavigationController = ({
- LearnDrivingVC *communityPageViewController = [[LearnDrivingVC alloc] initWithViewModel:self.viewModel.communityViewModel];
-
- RQTabBarItemTagType tagType = RQTabBarItemTagTypeCommunity;
- /// 配置
- [self rq_configViewController:communityPageViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];
- /// 添加到导航栏的栈底控制器
- [[RQBaseNavigationController alloc] initWithRootViewController:communityPageViewController];
- });
-
- /// 报名点
- UINavigationController *discoverPageNavigationController = ({
- NeighbouringVC *discoverPageViewController = [[NeighbouringVC alloc] initWithViewModel:self.viewModel.discoverViewModel];
- discoverPageViewController.isPushed = NO;
- RQTabBarItemTagType tagType = RQTabBarItemTagTypeDiscover;
- /// 配置
- [self rq_configViewController:discoverPageViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];
- /// 添加到导航栏的栈底控制器
- [[RQBaseNavigationController alloc] initWithRootViewController:discoverPageViewController];
- });
- /// 我的
- UINavigationController *profileNavigationController = ({
- // RQProfileViewController *profileViewController = [[RQProfileViewController alloc] initWithViewModel:self.viewModel.profileViewModel];
- FunctionVC *profileViewController = [[FunctionVC alloc] initWithViewModel:self.viewModel.profileViewModel];
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
-
- } else {
- profileViewController.hidesBottomBarWhenPushed = NO;
- }
- RQTabBarItemTagType tagType = RQTabBarItemTagTypeProfile;
- /// 配置
- [self rq_configViewController:profileViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];
- [[RQBaseNavigationController alloc] initWithRootViewController:profileViewController];
- });
- /// 添加到tabBarController的子视图
- self.tabBarController.viewControllers = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? @[homePageNavigationController] : (RQ_COMMON_MANAGER.LN_SHEQU_OPEN? @[homePageNavigationController, communityPageNavigationController, profileNavigationController] : @[homePageNavigationController, profileNavigationController]);
- /// 配置栈底
- [RQSharedAppDelegate.navigationControllerStack pushNavigationController:homePageNavigationController];
- }
- - (void)rq_configViewController:(UIViewController *)viewController imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName title:(NSString *)title itemTag:(RQTabBarItemTagType)tagType {
-
- UIImage *image = [[UIImage imageNamed:imageName] tint:[UIColor grayColor]];
- image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- viewController.tabBarItem.image = image;
- viewController.tabBarItem.tag = tagType;
-
- UIImage *selectedImage = [[UIImage imageNamed:selectedImageName] tint:RQ_MAIN_COLOR];
- selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- viewController.tabBarItem.selectedImage = selectedImage;
- viewController.tabBarItem.title = title;
-
- NSDictionary *normalAttr = @{NSForegroundColorAttributeName:RQ_MAIN_TEXT_COLOR_2,
- NSFontAttributeName:RQRegularFont_13};
- NSDictionary *selectedAttr = @{NSForegroundColorAttributeName:RQ_MAIN_COLOR,
- NSFontAttributeName:RQRegularFont_13};
- [viewController.tabBarItem setTitleTextAttributes:normalAttr forState:UIControlStateNormal];
- [viewController.tabBarItem setTitleTextAttributes:selectedAttr forState:UIControlStateSelected];
-
- [viewController.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, 0)];
- [viewController.tabBarItem setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
- }
- #pragma mark - UITabBarControllerDelegate
- - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
- if ([viewController.tabBarItem.title isEqualToString:@"个人"] || [viewController.tabBarItem.title isEqualToString:@"计时"]) {
- // return RQ_USER_MANAGER.isShouldLogin;
- if (!myDelegate.isLogin) {
- LoginViewController* vc = [[LoginViewController alloc] init];
- vc.modalPresentationStyle = UIModalPresentationFullScreen;
- [self presentViewController:vc animated:YES completion:nil];
- }
- return myDelegate.isLogin;
- } else {
- return YES;
- }
- }
- - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
- NSLog(@"viewController %@ %zd",viewController,viewController.tabBarItem.tag);
- [RQSharedAppDelegate.navigationControllerStack popNavigationController];
- [RQSharedAppDelegate.navigationControllerStack pushNavigationController:(UINavigationController *)viewController];
- }
- @end
|