123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 |
- //
- // YOUPAILCTabBarVC.m
- // LiveChat
- //
- // Created by 张灿 on 2018/4/6.
- // Copyright © 2018年 DaTongIntelligent. All rights reserved.
- //
- #import "YOUPAILCTabBarVC.h"
- #import "YMHomePageViewController.h"
- #import "YMHomeController.h"
- #import "YMDynamicViewController.h"
- #import "YMRankingViewController.h"
- #import "YMMineViewController.h"
- #import "YOUPAILCMessageVC.h"
- #import "YOUPAILCVerifyBigCastVC.h"
- #import "YOUPAILCBoardVC.h"
- #import "YOUPAILCMsgVC.h"
- #import "YOUPAILZLiveVC.h"
- #import "YOUPAIHRChatRoomHomeVC.h"
- #import "AppDelegate.h"
- #import "YOUPAILZProfileVC.h"
- #import "YOUPAILZDiscoverVC.h"
- #import "YOUPAIBBProfileVC.h"
- #import "YOUPAIBBMsgVC.h"
- #import "YOUPAILZHomeVC.h"
- @interface YOUPAILCTabBarVC ()<NIMConversationManagerDelegate,UITabBarDelegate,UITabBarControllerDelegate>
- @property(nonatomic,assign)NSInteger youpaipindexFlag;
- @property(nonatomic,assign)NSInteger youpaipcurrentIndex;
- @end
- @implementation YOUPAILCTabBarVC
- ///<NIMConversationManagerDelegate>
- + (instancetype)instance{
- AppDelegate *delegete = (AppDelegate *)[UIApplication sharedApplication].delegate;
- UIViewController *vc = delegete.window.rootViewController;
- if ([vc isKindOfClass:[YOUPAILCTabBarVC class]]) {
- return (YOUPAILCTabBarVC *)vc;
- }else{
- return nil;
- }
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [[NIMSDK sharedSDK].conversationManager addDelegate:self];
- [self youpaifupdateUnread];
- }
- #pragma mark 修复严重内存泄漏1
- //add by leo delegate 要移除
- -(void)viewWillDisappear:(BOOL)animated
- {
- NSLog(@"tabbar viewWillDisappear");
- [super viewWillDisappear:YES];
- //modify by leo 不移除 又内存泄漏
- [[NIMSDK sharedSDK].conversationManager removeDelegate:self];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.delegate = self;
- [self youpaifsetUpAllChildVc];
- // self.delegate = self;
- //创建自己的tabbar,然后用KVC将自己的tabbar和系统的tabBar替换下
- YOUPAILCTabBar *tabbar = [[YOUPAILCTabBar alloc] init];
- tabbar.itemPositioning = UITabBarItemPositioningFill;
- tabbar.tintColor = DecColorFromRGBA(0, 0, 0, 1);//HexColorFromRGB(0xA7A9FD);
-
- // [self.tabBarItem setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:10]} forState: UIControlStateNormal];
- // [self.tabBarItem setTitleTextAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:12]} forState: UIControlStateSelected];
-
-
- // tabbar.barTintColor = LCTextNormal;
- if (@available(iOS 10.0, *)) {
- tabbar.unselectedItemTintColor = DecColorFromRGBA(0, 0, 0, 0.6);
- } else {
- // Fallback on earlier versions
- }
- tabbar.backgroundColor = [UIColor whiteColor];
- // tabbar.block = ^{
- // if ([LCSaveModel getUserModel].userinfo.is_anchor ==1) {
- // LCTabCenterView* centerView = [[LCTabCenterView alloc]init];
- // [self.view addSubview:centerView];
- // }else{
- // ZCBaseNavigationVC* nav = (ZCBaseNavigationVC*)self.selectedViewController;
- // YOUPAILCVerifyBigCastVC* verify = [[YOUPAILCVerifyBigCastVC alloc]init];
- // [nav.viewControllers[0].navigationController pushViewController:verify animated:YES];
- // }
- // };
- self.youpaiptabbar = tabbar;
- // self.tabBar.delegate = self;
- //KVC实质是修改了系统的_tabBar
- [self setValue:tabbar forKeyPath:@"tabBar"];
- self.selectedIndex = 0;
- self.youpaipindexFlag = 0;
- [[NIMSDK sharedSDK].conversationManager addDelegate:self];
- [self youpaifupdateUnread];
-
- // for (int i = 0; i< self.tabbar.subviews.count; i++) {
- // UIView *tabBarButton = self.tabBar.subviews[i];
- //
- // tabBarButton.tag = i;
- // if (i < 2) {
- // UITapGestureRecognizer *doubleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(DoubleTap:)];
- // doubleRecognizer.numberOfTapsRequired = 2;// 双击
- // [tabBarButton addGestureRecognizer:doubleRecognizer];
- // }
- // }
- }
- //-(void)DoubleTap:(UITapGestureRecognizer *)tap
- //{
- // NSInteger index = tap.view.tag;
- // if (self.currentIndex == index && self.currentIndex == 0) {
- // //
- // }else {
- //
- // }
- //
- //}
- - (void)youpaifupdateUnread{
-
- if ([LCSaveData getWhiteVersion]) {
- NIMSession *session1 = [NIMSession session:@"2" type:NIMSessionTypeP2P];
- [[NIMSDK sharedSDK].conversationManager markAllMessagesReadInSession:session1];
- NIMSession *session2 = [NIMSession session:@"11" type:NIMSessionTypeP2P];
- [[NIMSDK sharedSDK].conversationManager markAllMessagesReadInSession:session2];
- }
-
-
- NSInteger unread = [[NIMSDK sharedSDK].conversationManager allUnreadCount];
- NSInteger item = [LCSaveData getWhiteVersion] ? 3 : 3;
- UITabBarItem* msgItm = self.youpaiptabbar.items[item];
- if (unread>0) {
- if (@available(iOS 10.0, *)) {
- msgItm.badgeColor = ZYGradientTwoColor;
- } else {
- // Fallback on earlier versions
- }
- if (unread>99) {
- msgItm.badgeValue = @"99+";
- }else{
- msgItm.badgeValue = [NSString stringWithFormat:@"%zd",unread];
- }
- }else{
- msgItm.badgeValue = nil;
- }
-
- }
- #pragma mark - 会话代理
- - (void)allMessagesRead{
- [self youpaifupdateUnread];
-
- }
- - (void)didAddRecentSession:(NIMRecentSession *)recentSession
- totalUnreadCount:(NSInteger)totalUnreadCount{
- [self youpaifupdateUnread];
- }
- - (void)didUpdateRecentSession:(NIMRecentSession *)recentSession
- totalUnreadCount:(NSInteger)totalUnreadCount{
- [self youpaifupdateUnread];
- }
- - (void)didRemoveRecentSession:(NIMRecentSession *)recentSession
- totalUnreadCount:(NSInteger)totalUnreadCount{
- [self youpaifupdateUnread];
- }
- - (void)messagesDeletedInSession:(NIMSession *)session{
- [self youpaifupdateUnread];
- }
- - (void)allMessagesDeleted{
- [self youpaifupdateUnread];
- }
- #pragma mark - setup
- - (void)youpaifsetUpAllChildVc {
-
- // if ([LCSaveData getWhiteVersion]) {
- //
- //// YOUPAIHRChatRoomHomeVC *liveVC = [[YOUPAIHRChatRoomHomeVC alloc] init];
- //// [self setupOneChildVcWithVc:liveVC image:@"vqu_images_tab_party_s" selectedImage:@"vqu_images_tab_party_n" title:@"派对"];
- //
- //
- // YOUPAILZHomeVC *home = [[YOUPAILZHomeVC alloc] init];
- // [self setupOneChildVcWithVc:home image:@"vqu_images_tab_fate_n" selectedImage:@"vqu_images_tab_fate_s" title:@"缘分"];
- //
- // YOUPAILZDiscoverVC *discover = [[YOUPAILZDiscoverVC alloc] init];
- // [self setupOneChildVcWithVc:discover image:@"vqu_images_tab_dynamic_n" selectedImage:@"vqu_images_tab_dynamic_s" title:@"动态"];
- //
- // YOUPAIBBMsgVC *chat =[[YOUPAIBBMsgVC alloc]init];
- // [self setupOneChildVcWithVc:chat image:@"vqu_images_tab_chat_n-1" selectedImage:@"vqu_images_tab_chat_s-1" title:@"消息"];
- //
- // YOUPAIBBProfileVC *mineVc = [[YOUPAIBBProfileVC alloc] init];
- // [self setupOneChildVcWithVc:mineVc image:@"vqu_images_tab_my_n-1" selectedImage:@"vqu_images_tab_my_s-1" title:@"我的"];
- //
- // }else{
-
- // YOUPAIHRChatRoomHomeVC *liveVC = [[YOUPAIHRChatRoomHomeVC alloc] init];
- // [self setupOneChildVcWithVc:liveVC image:@"vqu_images_tab_party_s" selectedImage:@"vqu_images_tab_party_n" title:@"派对"];
-
-
- YMHomePageViewModel *homeVM = [[YMHomePageViewModel alloc]initWithParams:@{}];
- // // 女号
- // if (homeVM.isFemaleGender) {
- // YMHomeController *homeVC = [[YMHomeController alloc]initWithViewModel:homeVM];
- // [self setupOneChildVcWithVc:homeVC image:@"ym_tabbar_home_page_normal_icon" selectedImage:@"ym_tabbar_home_page_selected_icon" title:@"首页"];
- // }
- // // 男号
- // else {
- // }
- YMHomePageViewController *homeVC = [[YMHomePageViewController alloc]initWithViewModel:homeVM];
- [self setupOneChildVcWithVc:homeVC image:@"ym_tabbar_home_page_normal_icon" selectedImage:@"ym_tabbar_home_page_selected_icon" title:@"首页"];
-
-
- // YOUPAILZHomeVC *home = [[YOUPAILZHomeVC alloc] init];
- // [self setupOneChildVcWithVc:home image:@"vqu_images_tab_fate_n" selectedImage:@"vqu_images_tab_fate_s" title:@"缘分"];
-
- // YMDynamicViewModel *dynamicVM = [[YMDynamicViewModel alloc]initWithParams:@{}];
- // YMDynamicViewController *dynamicVC = [[YMDynamicViewController alloc]initWithViewModel:dynamicVM];
- // [self setupOneChildVcWithVc:dynamicVC image:@"ym_tabbar_dynamic_normal_icon" selectedImage:@"ym_tabbar_dynamic_selected_icon" title:@"动态"];
-
- YOUPAILZDiscoverVC *discover = [[YOUPAILZDiscoverVC alloc] init];
- [self setupOneChildVcWithVc:discover image:@"ym_tabbar_dynamic_normal_icon" selectedImage:@"ym_tabbar_dynamic_selected_icon" title:@"动态"];
-
-
- YMRankingViewModel *rankingVM = [[YMRankingViewModel alloc]initWithParams:@{}];
- YMRankingViewController *rankingVC = [[YMRankingViewController alloc]initWithViewModel:rankingVM];
- [self setupOneChildVcWithVc:rankingVC image:@"ym_tabbar_ranking_normal_icon" selectedImage:@"ym_tabbar_ranking_selected_icon" title:@"榜单"];
-
-
- // YOUPAILCBoardVC *board = [[YOUPAILCBoardVC alloc]init];
- // board.youpaiptype = 0;
- // board.youpaiphiddenBack = YES;
- // [self setupOneChildVcWithVc:board image:@"vqu_images_tab_rank_n" selectedImage:@"vqu_images_tab_rank_s" title:@"榜单"];
-
- // YOUPAILZLiveVC *liveVC = [[YOUPAILZLiveVC alloc] init];
- // ZCBaseWebVC* baseWeb = [[ZCBaseWebVC alloc]init];
- // baseWeb.contentUrl = [LCSaveData getRankH5Url];
- // [LCHttpHelper requestWithURLString:AppConfig parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- // NSDictionary* dict = (NSDictionary*)responseObject;
- // NSInteger code = [[dict objectForKey:@"code"] integerValue];
- // if (code==0) {//成功
- // NSString *rankH5Url = [[dict objectForKey:@"data"]objectForKey:@"rank_url_full"];
- // [LCSaveData saveRankH5Url:rankH5Url];
- // baseWeb.contentUrl = [LCSaveData getRankH5Url];
- // [baseWeb reloadWebView];
- // }
- // } failure:^(NSError *error) {
- //
- // }];
- // baseWeb.needHideNav = YES;
- // [self setupOneChildVcWithVc:baseWeb image:@"vqu_images_tabbar_board_n" selectedImage:@"vqu_images_tabbar_board_s" title:@"榜单"];
-
- // YOUPAILCMessageVC *chat = [[YOUPAILCMessageVC alloc]init];
- //modify by leo 20191030
-
- YOUPAILCMsgVC *chat =[[YOUPAILCMsgVC alloc]init];
- [self setupOneChildVcWithVc:chat image:@"ym_tabbar_messages_normal_icon" selectedImage:@"ym_tabbar_messages_selected_icon" title:@"消息"];
-
- YMMineViewModel *mineVM = [[YMMineViewModel alloc]initWithParams:@{}];
- YMMineViewController *mineVC = [[YMMineViewController alloc]initWithViewModel:mineVM];
- [self setupOneChildVcWithVc:mineVC image:@"ym_tabbar_mine_normal_icon" selectedImage:@"ym_tabbar_mine_selected_icon" title:@"我的"];
-
- // YOUPAILZProfileVC *mineVc = [[YOUPAILZProfileVC alloc] init];
- // [self setupOneChildVcWithVc:mineVc image:@"vqu_images_tab_my_n-1" selectedImage:@"vqu_images_tab_my_s-1" title:@"我的"];
-
-
- // }
-
-
- }
- - (void)setupOneChildVcWithVc:(UIViewController *)VC image:(NSString *)image selectedImage:(NSString *)selectedImage title:(NSString *)title {
-
- ZCBaseNavigationVC *nav = [[ZCBaseNavigationVC alloc] initWithRootViewController:VC];
- VC.tabBarItem.title = title;
-
-
- VC.tabBarItem.image = [[UIImage imageNamed:image]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- VC.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
-
- // VC.tabBarItem.image = [UIImage imageNamed:image];
- // VC.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
-
- VC.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -4);
- [self addChildViewController:nav];
-
- NSLog(@"%@",self.viewControllers);
-
-
- }
- - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
- NSInteger index = [self.tabBar.items indexOfObject:item];
- self.youpaipcurrentIndex = index;
-
- NSLog(@"index === %ld",index);
-
- // if (index==2) {
- // [self.tabbar youpaifupdateCenterBtn:YES];
- // }else{
- // [self.tabbar youpaifupdateCenterBtn:NO];
- // }
- // if (self.indexFlag != index) {
- // [self youpaifanimationWithIndex:index];
- // }
- //MARK: 埋点
- if (index == 0) {
- [UMengRecordTool umengEventCountWithId:FrontPage];
- }
- else if (index == 1) {
- [UMengRecordTool umengEventCountWithId:EnterDynamicPage];
- }else if (index == 2){
-
- }else if (index == 3){
- [UMengRecordTool umengEventCountWithId:EnterMessageList];
- }
- else if (index == 4){
- [UMengRecordTool umengEventCountWithId:EnterMyPage];
- }
- if (index == 1 && kAppDelegate.isDisplayVideoDynamicPage) {
-
- // self.tabbar.tintColor = LCWhiteColor;
- // if (@available(iOS 10.0, *)) {
- // self.tabbar.unselectedItemTintColor = HexColorFromRGBA(0xffffff,0.38);
- // } else {
- //
- // }
-
- [self.youpaiptabbar youpaifupdateCenterBtn:YES];
-
-
- }else{
- // self.tabbar.tintColor = HexColorFromRGB(0xA7A9FD);
- // if (@available(iOS 10.0, *)) {
- //
- // self.tabbar.unselectedItemTintColor = LCTextNormal;
- //
- // } else {
- //
- // }
-
- [self.youpaiptabbar youpaifupdateCenterBtn:NO];
- }
- self.youpaiptabbar.backgroundColor = [UIColor whiteColor];
- }
- - (void)youpaifanimationWithIndex:(NSInteger) index {
-
- NSMutableArray * tabbarbuttonArray = [NSMutableArray array];
-
- for (UIView *tabBarButton in self.tabBar.subviews) {
-
- if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
- [tabbarbuttonArray addObject:tabBarButton];
- }
- }
- CABasicAnimation*pulse = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
- pulse.timingFunction= [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- pulse.duration = 0.12;
- pulse.repeatCount= 1;
- pulse.autoreverses= NO;
- pulse.fromValue= [NSNumber numberWithFloat:0.9];
- pulse.toValue= [NSNumber numberWithFloat:1.0];
- UIView *tabBarButton = [tabbarbuttonArray objectAtIndex:index];
- [[tabBarButton layer] addAnimation:pulse forKey:nil];
- //MODIFY BY LEO FIX BUG IOS13 --20191008
- /*
- [[tabbarbuttonArray[index] layer]
-
- addAnimation:pulse forKey:nil];
- */
- self.youpaipindexFlag = index;
- }
- #pragma mark 修复严重内存泄漏3
- -(void)dealloc
- {
- NSLog(@"TabBarVC delloc");
- }
- - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
- // NSInteger index = [tabBarController.childViewControllers indexOfObject:viewController];
- //
- // UIButton *tabBarBtn = tabBarController.tabBar.subviews[index+1];
- // UIImageView *imageView = tabBarBtn.subviews.firstObject;
- //
- // // 我们把动画加到这个imageView上,即可实现动画效果
- //
- // // ......
-
-
- //双击那个item
- // if (tabBarController.selectedIndex == 1) {
- // self.youpaiptabbar.backgroundColor = HexColorFromRGB(0x2A2935);
- // if ([self youpaifcheckIsDoubleClick:viewController]) {
- // [[NSNotificationCenter defaultCenter] postNotificationName:@"homeToTop" object:nil];//首页置顶
- // }
- // }
- // if (tabBarController.selectedIndex == 2) {
- // self.youpaiptabbar.backgroundColor = HexColorFromRGB(0x2A2935);
- // if ([self youpaifcheckIsDoubleClick:viewController]) {
- // if (kAppDelegate.isDisplayVideoDynamicPage) {//视频
- // [[NSNotificationCenter defaultCenter] postNotificationName:@"videoToTop" object:nil];//视频置顶
- // }else{//动态
- // self.youpaiptabbar.backgroundColor = HexColorFromRGB(0x2A2935);
- // [[NSNotificationCenter defaultCenter] postNotificationName:@"dynamicToTop" object:nil];//动态置顶
- // }
- //
- // }
- // }
-
- return YES;
- }
- - (BOOL)youpaifcheckIsDoubleClick:(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 > 3 ) {
- lastClickTime = clickTime;
- return NO;
- }
- lastClickTime = clickTime;
- return YES;
- }
- @end
|