345 lines
14 KiB
Objective-C
345 lines
14 KiB
Objective-C
//
|
|
// 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 <ImSDK_Plus/ImSDK_Plus.h>
|
|
#import "QXMessageServices.h"
|
|
|
|
#import "QXMeetActivityDriftView.h" // 巡乐会
|
|
#import "QXChirldModeViewController.h"
|
|
#import "QXAppVersionView.h"
|
|
#import "QXLoginNetwork.h"
|
|
|
|
@interface QXTabbarController ()<UITabBarControllerDelegate,QXTabBarDelegate,UINavigationControllerDelegate,MQTTClientModelDelegate,V2TIMConversationListener>
|
|
@property(nonatomic,strong) QXTabBar *customTabBar;
|
|
@property(nonatomic,strong) QXHomeViewController *homeVC;
|
|
@property(nonatomic,strong) QXMeetActivityDriftView *meetView;
|
|
@property(nonatomic,assign) BOOL isAlreadyShowChirld;
|
|
@property(nonatomic,strong) QXAppVersionView *appUpdateView;
|
|
@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];
|
|
[self popChirldView];
|
|
}
|
|
QXLOG(@"视图即将展示");
|
|
[self getAppVersion];
|
|
}
|
|
|
|
-(void)getAppVersion{
|
|
MJWeakSelf
|
|
[QXLoginNetwork getAppVersionSuccessBlock:^(QXAppVersionModel * _Nonnull model) {
|
|
|
|
NSString *currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
|
|
NSString *latestVersion = model.version; // 从服务器获取的最新版本
|
|
NSInteger result = [QXVersionComparator compareVersion:latestVersion withOldVersion:currentVersion];
|
|
switch (result) {
|
|
case 1:
|
|
NSLog(@"需要更新:新版本 %@ 比当前版本 %@ 新", latestVersion, currentVersion);
|
|
weakSelf.appUpdateView.model = model;
|
|
[weakSelf.appUpdateView showInView:KEYWINDOW];
|
|
break;
|
|
case 0:
|
|
NSLog(@"版本相同:当前版本 %@ 已是最新", currentVersion);
|
|
break;
|
|
case -1:
|
|
NSLog(@"版本异常:新版本 %@ 比当前版本 %@ 旧", latestVersion, currentVersion);
|
|
break;
|
|
}
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
|
|
}];
|
|
}
|
|
#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{
|
|
QXChirldModeViewController *vc = [[QXChirldModeViewController alloc] init];
|
|
vc.type = 0;
|
|
[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{
|
|
if ([topic isEqualToString:qx_room_topic]) {
|
|
// NSDictionary*dict = message[@"msg"];
|
|
// BOOL isList = YES;
|
|
// for (NSString *key in dict.allKeys) {
|
|
// if ([key isEqualToString:@"list"]) {
|
|
// isList = NO;
|
|
// break;
|
|
// }
|
|
// }
|
|
// if (isList) {
|
|
NSArray *array = [NSArray yy_modelArrayWithClass:[QXGiftScrollModel class] json:message[@"msg"][@"list"]];
|
|
if (array.count == 0) {
|
|
return;
|
|
}
|
|
[self.homeVC giftScrollViewShowWithModelList:array];
|
|
[[QXGiftDriftView shareView] addGiftModelList:array];
|
|
// }else{
|
|
// QXGiftScrollModel *model = [QXGiftScrollModel yy_modelWithJSON:message[@"msg"][@"list"]];
|
|
// [self.homeVC giftScrollViewShowWithModel:model];
|
|
// [[QXGiftDriftView shareView] addGiftModel:model];
|
|
// }
|
|
}else if([topic isEqualToString:qx_ac_topic]){
|
|
QXMeetActivityDriftModel *model = [QXMeetActivityDriftModel yy_modelWithJSON:message[@"msg"]];
|
|
[[QXMeetActivityDriftView shareView] addActivityModel:model];
|
|
}
|
|
|
|
}
|
|
|
|
-(QXAppVersionView *)appUpdateView{
|
|
if (!_appUpdateView) {
|
|
_appUpdateView = [[QXAppVersionView alloc] init];
|
|
}
|
|
return _appUpdateView;
|
|
}
|
|
|
|
//-(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
|