123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- //
- // InstitutionTabBarController.m
- // KulexiuForStudent
- //
- // Created by 王智 on 2023/9/11.
- //
- #import "InstitutionTabBarController.h"
- #import "InstitutionNavController.h"
- #import "KSBaseViewController.h"
- #import "KSTenantHomeViewController.h"
- #import "ChatViewController.h"
- #import "InsititutionMineViewController.h"
- #import <UIImage+Color.h>
- #import "AnimationHelper.h"
- #import "MineWorksViewController.h"
- #import "CustomNavViewController.h"
- @interface InstitutionTabBarController ()<UITabBarControllerDelegate>
- @end
- @implementation InstitutionTabBarController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.delegate = self;
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showDraftPage) name:@"DisplayDraft" object:nil];
- [self configItems];
- }
- - (void)showDraftPage {
- [self tabBarSelectedWithIndex:2];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- CustomNavViewController *navCtrl = self.selectedViewController;
- MineWorksViewController *ctrl = [[MineWorksViewController alloc] init];
- [ctrl displayDraft:YES];
- [navCtrl pushViewController:ctrl animated:YES];
- });
- }
- - (void)configItems {
- // 处理 pad上 tabbar样式
- if (@available(iOS 18.0, *)) {
- if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
- {
- self.traitOverrides.horizontalSizeClass = UIUserInterfaceSizeClassCompact; //TAB BAR ON BOTTOM
- }
- }
- NSArray *controllerArray = @[@"KSTenantHomeViewController",@"ChatViewController",@"InsititutionMineViewController"];
- NSArray *titleArray = @[@"首页",@"通讯",@"我的"];
- NSArray *imageArray = @[@"tenant_tab_home_unselected",@"tenant_tab_chat_unselected",@"tetant_tab_mine_unselected"];
- NSArray *selectedImgArray = @[@"tenant_tab_home_selected",@"tenant_tab_chat_selected",@"tetant_tab_mine_selected"];
- NSMutableArray *ctrlArray = [NSMutableArray array];
- for (NSInteger i = 0; i < controllerArray.count; i++) {
- CustomNavViewController *navCtrl = [self createNavControllerWithClassName:controllerArray[i] title:titleArray[i] imageName:imageArray[i] selectedImageName:selectedImgArray[i]];
- [ctrlArray addObject:navCtrl];
- }
- self.viewControllers = [NSArray arrayWithArray:ctrlArray];
- if (@available(iOS 13.0, *)) {
- [[UITabBar appearance] setUnselectedItemTintColor:HexRGB(0x999999)];
- [[UITabBar appearance] setTintColor:INS_THEMECOLOR];
- } else {
- [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:HexRGB(0x999999),NSFontAttributeName:[UIFont systemFontOfSize:10 weight:UIFontWeightMedium]} forState:UIControlStateNormal];
- [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:INS_THEMECOLOR,NSFontAttributeName:[UIFont systemFontOfSize:10 weight:UIFontWeightMedium]} forState:UIControlStateSelected];
- }
- if (@available(iOS 15.0, *)) {
- // 适配Xcode 13 iOS 15tabbar透明的问题
- UITabBarAppearance * appearance = [[UITabBarAppearance alloc] init];
- [appearance configureWithOpaqueBackground];
- appearance.backgroundColor = UIColor.whiteColor;
- appearance.shadowImage = [UIImage imageWithColor:[UIColor clearColor]];
- [UITabBar appearance].scrollEdgeAppearance = appearance;
- [UITabBar appearance].standardAppearance = appearance;
- }
- [UITabBar appearance].backgroundColor = UIColor.whiteColor;
- self.tabBar.translucent = NO;
- [self changeTabBarColor:HexRGB(0x121B2E)];
- }
- - (CustomNavViewController *)createNavControllerWithClassName:(NSString *)className title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName {
- KSBaseViewController *controller = [[NSClassFromString(className) alloc] init];
- controller.title = title;
- controller.tabBarItem.title = title;
- controller.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- controller.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- [controller.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:HexRGB(0xAAAAAA),NSFontAttributeName:[UIFont systemFontOfSize:10 weight:UIFontWeightMedium]} forState:UIControlStateNormal];
- [controller.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:HexRGB(0xFF497B),NSFontAttributeName:[UIFont systemFontOfSize:10 weight:UIFontWeightMedium]} forState:UIControlStateSelected];
- CustomNavViewController *navCtrl= [[CustomNavViewController alloc] initWithRootViewController:controller];
- return navCtrl;
- }
- - (void)changeBgColorWithTabBarController:(UITabBarController *)tabBarController selectViewController:(UIViewController *)viewController {
- if ([viewController isKindOfClass:[CustomNavViewController class]]) {
- CustomNavViewController *navCtrl = (CustomNavViewController *)viewController;
- UIViewController *childrenCtrl = [navCtrl.visibleViewController.childViewControllers lastObject];
- if ([childrenCtrl isMemberOfClass:NSClassFromString(@"TenantDarkViewController")]) {
- [self changeTabBarColor:HexRGB(0x121B2E)];
- }
- else {
- [self resetTabBarColor];
- }
- }
- }
- - (void)tabBarSelectedWithIndex:(NSInteger)index {
- if (index >= 2) { // 跳转到聊天
- index -= 1;
- }
- [self setSelectedIndex:index];
- UIViewController *controller = [self.viewControllers objectAtIndex:index];
- [self changeBgColorWithTabBarController:self selectViewController:controller];
- }
- #pragma mark ----- UITabBarControllerDelegate
- - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
- BOOL isDoubleClick = [self checkIsDoubleClick:viewController];
- if ([viewController isEqual:[tabBarController.viewControllers objectAtIndex:2]] && isDoubleClick) {
- [[NSNotificationCenter defaultCenter] postNotificationName:CHATVIEW_REFRESH object:nil];
- }
-
- [self changeBgColorWithTabBarController:tabBarController selectViewController:viewController];
-
- // [self setAnaimationWithTabBarController:tabBarController selectViewController:viewController];
- }
- - (void)setAnaimationWithTabBarController:(UITabBarController *)tabBarController selectViewController:(UIViewController *)viewController {
- //1.
- NSInteger index = [tabBarController.viewControllers indexOfObject:viewController];
- __block NSMutableArray <UIView *>*tabBarSwappableImageViews = [NSMutableArray arrayWithCapacity:4];
- //2.
- for (UIView *tempView in tabBarController.tabBar.subviews) {
- if ([tempView isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
- for (UIImageView *tempImageView in tempView.subviews) {
- if ([tempImageView isKindOfClass:NSClassFromString(@"UITabBarSwappableImageView")]) {
- [tabBarSwappableImageViews addObject:tempImageView];
- }
- }
- }
- }
- //3.
- __block UIView *currentTabBarSwappableImageView = tabBarSwappableImageViews[index];
- [AnimationHelper lottieAnimation:currentTabBarSwappableImageView index:index];
- }
- - (BOOL)checkIsDoubleClick:(UIViewController *)viewController {
- static UIViewController *lastViewController = nil;
- static NSTimeInterval lastClickTime = 0;
- if (lastViewController != viewController) {
-
- lastViewController = viewController;
- lastClickTime = [NSDate timeIntervalSinceReferenceDate];
- return NO;
- }
- NSTimeInterval clickTime = [NSDate timeIntervalSinceReferenceDate];
- if (clickTime - lastClickTime > 0.5) {
-
- lastClickTime = clickTime;
- return NO;
- }
- lastViewController = nil;
- lastClickTime = 0;
- return YES;
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|