// // QXTabbarController.m // QXLive // // Created by 启星 on 2025/4/24. // #import "QXTabbarController.h" #import "QXDynamicViewController.h" #import "QXHomeViewController.h" #import "QXLoginViewController.h" #import "QXMessageViewController.h" #import "QXMineViewController.h" #import "QXPartyViewController.h" #import "QXBaseNavigationController.h" #import "QXLoginViewController.h" #import "QXTabbarConfig.h" #import "QXTabBar.h" #import "QXChirldViewController.h" #import "QXManagerMqtt.h" #import "QXGiftScrollView.h" //弹窗 #import "QXChirldPopView.h" // 青少年 #import "QXNiceGiftPopView.h" // 天降好礼 #import "QXFirstRechargePopView.h" // 首充 #import "QXInvitePopView.h" // 邀请 #import "QXGiftDriftView.h" // 礼物飘屏 #import #import "QXMessageServices.h" @interface QXTabbarController () @property(nonatomic,strong) QXTabBar *customTabBar; @property(nonatomic,strong) QXHomeViewController *homeVC; @property(nonatomic,assign) BOOL isAlreadyShowChirld; @end @implementation QXTabbarController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.delegate = self; [self setupTabbar]; [self configChildVC]; // [self performSelector:@selector(giftAction) afterDelay:7]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; if (self.isAlreadyShowChirld) { return; } if (QXGlobal.shareGlobal.isLogin) { [self performSelector:@selector(popChirldView) afterDelay:1]; } QXLOG(@"视图即将展示"); } #pragma mark - 青少年模式 -(void)popChirldView{ self.isAlreadyShowChirld = YES; MJWeakSelf QXChirldPopView *view = [[QXChirldPopView alloc] init]; view.closeActionBlock = ^{ [[QXGlobal shareGlobal].alertViewController hideViewFinishBlock:^{ QXLOG(@"页面关闭"); // [weakSelf popNiceGiftView]; }]; }; view.gotoActionBlock = ^{ [[QXGlobal shareGlobal].alertViewController hideViewFinishBlock:^{ QXLOG(@"页面关闭"); [weakSelf pushToChirld]; }]; }; view.setActionBlock = ^{ [[QXGlobal shareGlobal].alertViewController hideViewFinishBlock:^{ QXLOG(@"页面关闭"); }]; }; [[QXGlobal shareGlobal] showView:view controller:self.homeVC popType:(PopViewTypeTopToCenter) tapDismiss:NO finishBlock:^{ }]; } -(void)pushToChirld{ QXChirldViewController *vc = [[QXChirldViewController alloc] init]; [self.navigationController pushViewController:vc animated:YES]; } -(void)popFirstRechargeView{ MJWeakSelf // QXFirstRechargePopView *view = [[QXFirstRechargePopView alloc] init]; // view.giftArray = @[@"",@"",@"",@"",@"",@""]; // view.closeActionBlock = ^{ // [[QXGlobal shareGlobal].alertViewController hideViewFinishBlock:^{ // QXLOG(@"页面关闭"); // [weakSelf popInvitePopView]; // }]; // }; // view.rechargeActionBlock = ^{ // [[QXGlobal shareGlobal].alertViewController hideViewFinishBlock:^{ // QXLOG(@"页面关闭"); // }]; // }; // [[QXGlobal shareGlobal] showView:view popType:(PopViewTypeTopToCenter) tapDismiss:NO finishBlock:^{ // // }]; } -(void)popNiceGiftView{ MJWeakSelf QXNiceGiftPopView *view = [[QXNiceGiftPopView alloc] init]; view.closeActionBlock = ^{ [[QXGlobal shareGlobal].alertViewController hideViewFinishBlock:^{ QXLOG(@"页面关闭"); [weakSelf popFirstRechargeView]; }]; }; view.getActionBlock = ^{ [[QXGlobal shareGlobal].alertViewController hideViewFinishBlock:^{ QXLOG(@"页面关闭"); }]; }; view.ruleActionBlock = ^{ [[QXGlobal shareGlobal].alertViewController hideViewFinishBlock:^{ QXLOG(@"页面关闭"); }]; }; view.giftArray = @[@"",@"",@"",@"",@"",@""]; [[QXGlobal shareGlobal] showView:view popType:(PopViewTypeTopToCenter) tapDismiss:NO finishBlock:^{ }]; } -(void)popInvitePopView{ QXInvitePopView *view = [[QXInvitePopView alloc] init]; view.closeActionBlock = ^{ [[QXGlobal shareGlobal].alertViewController hideViewFinishBlock:^{ QXLOG(@"页面关闭"); }]; }; view.agreeActionBlock = ^{ }; [[QXGlobal shareGlobal] showView:view popType:(PopViewTypeTopToCenter) tapDismiss:NO finishBlock:^{ }]; } //解决tabbar被原生tabbar覆盖问题 - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animate{ if (navigationController.viewControllers.count == 1) { for (UIView *child in self.tabBar.subviews){ if ([child isKindOfClass:NSClassFromString(@"UITabBarButton")]){ [child removeFromSuperview]; } } } } - (void)setupTabbar { [self.tabBar removeAllSubviews]; self.tabBar.shadowImage = [UIImage new]; self.tabBar.backgroundImage = [UIImage new]; self.tabBar.backgroundColor = [UIColor clearColor]; // self.tabBarController.tabBar.standardAppearance = tabBar; // if (@available(iOS 15.0,*)) { // self.tabBarController.tabBar.scrollEdgeAppearance = tabBar; // } QXTabbarConfig *config = [QXTabbarConfig shareInstance]; config.imageOffset = -5; QXTabBar *customTabBar = [[QXTabBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, TabbarContentHeight) centerCustom:NO config:config]; customTabBar.backgroundColor = [UIColor whiteColor]; customTabBar.layer.shadowColor = [UIColor grayColor].CGColor; customTabBar.layer.shadowOpacity = 0.5; customTabBar.layer.shadowOffset = CGSizeMake(0, 2); customTabBar.layer.shadowRadius = 25.0; customTabBar.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:customTabBar.bounds cornerRadius:customTabBar.layer.cornerRadius].CGPath; customTabBar.delegate = self; // customTabBar.layer.cornerRadius = 25.0; // customTabBar.layer.masksToBounds = NO; self.selectedIndex = 0; // [self.view addSubview:customTabBar]; self.customTabBar = customTabBar; [self.tabBar addSubview:self.customTabBar]; [self.tabBar bringSubviewToFront:self.customTabBar]; } -(void)setMessageUnReadNumber:(UInt64)messageUnReadNumber{ _messageUnReadNumber = messageUnReadNumber; QXLOG(@"会话未读消息--%ld",_messageUnReadNumber); [self setUnReadNumber:self.messageUnReadNumber+self.systemUnreadNumber]; } -(void)setSystemUnreadNumber:(UInt64)systemUnreadNumber{ _systemUnreadNumber = systemUnreadNumber; QXLOG(@"系统未读消息--%ld",_systemUnreadNumber); [self setUnReadNumber:self.messageUnReadNumber+self.systemUnreadNumber]; } -(void)setUnReadNumber:(UInt64)unReadNumber{ _unReadNumber = unReadNumber; QXLOG(@"总计未读消息--%ld",_unReadNumber); self.customTabBar.unReadNumber = unReadNumber; } -(void)QXTabBar:(QXTabBar *)tabBar didSelectedButtonFrom:(NSInteger)from to:(NSInteger)to{ if (![QXGlobal shareGlobal].isLogin && to==QXConfig.tabbarArray.count-1) { QXLoginViewController *vc = [[QXLoginViewController alloc] init]; QXBaseNavigationController *na = [[QXBaseNavigationController alloc] initWithRootViewController:vc]; na.modalPresentationStyle = UIModalPresentationFullScreen; [self presentViewController:na animated:YES completion:nil]; return; } self.selectedIndex = to; } -(void)configChildVC{ [QXManagerMqtt sharedInstance].delegate = self; QXHomeViewController *homeVC = [[QXHomeViewController alloc] init]; self.homeVC = homeVC; // [self addChildVCWithTitle:@"首页" normalImage:[UIImage imageNamed:@"qx_tabbar_home_nor"] selectedImage:[UIImage imageNamed:@"qx_tabbar_home_sel"] controller:homeVC]; QXDynamicViewController *dynamicVC = [[QXDynamicViewController alloc] init]; // [self addChildVCWithTitle:@"动态" normalImage:[UIImage imageNamed:@"qx_tabbar_find_nor"] selectedImage:[UIImage imageNamed:@"qx_tabbar_find_sel"] controller:dynamicVC]; // QXPartyViewController *partyVC = [[QXPartyViewController alloc] init]; // [self addChildVCWithTitle:@"" normalImage:[UIImage imageNamed:@"qx_tabbar_party"] selectedImage:[UIImage imageNamed:@"qx_tabbar_party"] controller:partyVC]; QXMessageViewController *messageVC = [[QXMessageViewController alloc] init]; // [self addChildVCWithTitle:@"消息" normalImage:[UIImage imageNamed:@"qx_tabbar_message_nor"] selectedImage:[UIImage imageNamed:@"qx_tabbar_message_sel"] controller:messageVC]; QXMineViewController *mineVC = [[QXMineViewController alloc] init]; // [self addChildVCWithTitle:@"我的" normalImage:[UIImage imageNamed:@"qx_tabbar_me_nor"] selectedImage:[UIImage imageNamed:@"qx_tabbar_me_sel"] controller:mineVC]; NSArray *tabbarArray = QXConfig.tabbarArray; NSArray *controller = @[homeVC,dynamicVC,messageVC,mineVC]; for (int i =0; i < tabbarArray.count ;i++) { QXTabbarModel *model = tabbarArray[i]; UIViewController *vc = controller[i]; [self addChildVCWithTitle:model.title normalImage:model.normalImage selectedImage:model.selectedImage controller:vc]; } } -(void)addChildVCWithTitle:(NSString*)title normalImage:(NSString*)normalImage selectedImage:(NSString*)selectedImage controller:(UIViewController*)controller{ QXBaseNavigationController *na = [[QXBaseNavigationController alloc] initWithRootViewController:controller]; na.delegate = self; // UITabBarItem *item = [[UITabBarItem alloc] init]; // item.title = title; // item.image = [normalImage imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)]; // item.selectedImage = [selectedImage imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)]; // na.tabBarItem = item; [self addChildViewController:na]; [self.customTabBar addTabBarButtonNorImageUrl:normalImage selImageUrl:selectedImage title:title]; } -(void)socketManager:(NSString *)socketManager receivedMessage:(NSDictionary *)message topic:(NSString *)topic{ QXGiftScrollModel *model = [QXGiftScrollModel yy_modelWithJSON:message[@"msg"][@"list"]]; [self.homeVC giftScrollViewShowWithModel:model]; [[QXGiftDriftView shareView] addGiftModel:model]; } //-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{ // NSInteger index = [self.viewControllers indexOfObject:viewController]; // if (index == 4) { // //判断是否登录 // if (![QXGlobal shareGlobal].isLogin) { // QXLoginViewController *vc = [[QXLoginViewController alloc] init]; //// vc.hidesBottomBarWhenPushed = YES; //// [(QXBaseNavigationController*)tabBarController.selectedViewController pushViewController:vc animated:YES]; // QXBaseNavigationController *na = [[QXBaseNavigationController alloc] initWithRootViewController:vc]; // na.modalPresentationStyle = UIModalPresentationFullScreen; // [(QXBaseNavigationController*)tabBarController.selectedViewController presentViewController:na animated:YES completion:nil]; // return NO; // } // return YES; // } // return YES; //} @end