// // RQMainTabBarViewController.m // RQCommon // // Created by 张嵘 on 2018/11/21. // Copyright © 2018 张嵘. All rights reserved. // 主界面控制器 #import "RQMainTabBarViewController.h" #import "RQBaseNavigationController.h" @interface RQMainTabBarViewController () @property (nonatomic, readonly, strong) RQMainTabBarViewModel *viewModel; @end @implementation RQMainTabBarViewController @dynamic viewModel; #pragma mark - System - (void)viewDidLoad { [super viewDidLoad]; // 初始化所有的子控制器 [self rq_setupAllChildViewController]; // set delegate self.tabBarController.delegate = self; } #pragma mark - Private Method - (void)rq_setupAllChildViewController { NSArray *titlesArray = @[@"考试", @"社区", @"计时", @"我的"]; NSArray *imageNamesArray = @[@"考试灰", @"tabbarImg2", @"计时灰", @"我的灰" ]; NSArray *selectedImageNamesArray = @[@"考试蓝", @"tabbarImg2", @"计时蓝", @"我的蓝" ]; /// 首页-考试 RQBaseNavigationController *homePageNavigationController = ({ RQHomePageViewController *homePageViewController = [[RQHomePageViewController alloc] initWithViewModel:self.viewModel.homePageViewModel]; RQTabBarItemTagType tagType = RQTabBarItemTagTypeHomePage; /// 配置 [self rq_configViewController:homePageViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType]; /// 添加到导航栏的栈底控制器 homePageViewController.hidesBottomBarWhenPushed = NO; [[RQBaseNavigationController alloc] initWithRootViewController:homePageViewController]; }); /// 计时 RQBaseNavigationController *timePageNavigationController = ({ // TimingBaseVC *timePageViewController = [[TimingBaseVC alloc] initWithViewModel:self.viewModel.timeViewModel]; RQTimeViewController *timePageViewController = [[RQTimeViewController alloc] initWithViewModel:self.viewModel.timeViewModel]; RQTabBarItemTagType tagType = RQTabBarItemTagTypeTime; /// 配置 [self rq_configViewController:timePageViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType]; /// 添加到导航栏的栈底控制器 timePageViewController.hidesBottomBarWhenPushed = NO; [[RQBaseNavigationController alloc] initWithRootViewController:timePageViewController]; }); /// 我的 RQBaseNavigationController *profileNavigationController = ({ //#if DEBUG RQProfileViewController *profileViewController = [[RQProfileViewController alloc] initWithViewModel:self.viewModel.profileViewModel]; //#else // FunctionVC *profileViewController = [[FunctionVC alloc] initWithViewModel:self.viewModel.profileViewModel]; //#endif RQTabBarItemTagType tagType = RQTabBarItemTagTypeProfile; /// 配置 [self rq_configViewController:profileViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType]; profileViewController.hidesBottomBarWhenPushed = NO; [[RQBaseNavigationController alloc] initWithRootViewController:profileViewController]; }); /// 添加到tabBarController的子视图 self.tabBarController.viewControllers = @[homePageNavigationController, timePageNavigationController, 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_15}; NSDictionary *selectedAttr = @{NSForegroundColorAttributeName:RQ_MAIN_COLOR, NSFontAttributeName:RQRegularFont_15}; [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; } 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]; if ([viewController.tabBarItem.title isEqualToString:@"计时"] && [RQ_USER_MANAGER isQzVideo] && !RQ_COMMON_MANAGER.isQzLook) { RQNewFeatureViewModel *newFeatureViewModel = [[RQNewFeatureViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{RQViewCommonValueKey : @"quanzhou"}]; [RQ_APPDELEGATE.services presentViewModel:newFeatureViewModel animated:YES completion:^{ }]; } } @end