|
|
|
//
|
|
|
|
// UITabBarViewController.m
|
|
|
|
// myWatch
|
|
|
|
//
|
|
|
|
// Created by mobao on 15/10/9.
|
|
|
|
// Copyright (c) 2015年 xTT. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "MyTabBarViewController.h"
|
|
|
|
#import "AppDelegate.h"
|
|
|
|
#import "myHelper.h"
|
|
|
|
#import "MyMQTT.h"
|
|
|
|
#import "User.h"
|
|
|
|
//#import "WCADView.h"
|
|
|
|
#import "JCManager.h"
|
|
|
|
|
|
|
|
#import "WatchHomeViewController.h"
|
|
|
|
#import "HomeMessageViewController.h"
|
|
|
|
#import "MyViewController.h"
|
|
|
|
#import "MapViewController.h"
|
|
|
|
#import "TabBarVideoViewController.h"
|
|
|
|
|
|
|
|
#import "VideoTabPopView.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@interface MyTabBarViewController ()<UITabBarControllerDelegate>{
|
|
|
|
UIView *launchView;
|
|
|
|
NSString *LaunchImageName;
|
|
|
|
}
|
|
|
|
|
|
|
|
@property (nonatomic,strong) UIImageView *bottomView;
|
|
|
|
@property (nonatomic,strong) UIWindow *subWin;
|
|
|
|
//@property (nonatomic,strong) GDTSplashAd *splash;
|
|
|
|
@property (nonatomic,strong) UIImageView *TransitionImageView;
|
|
|
|
|
|
|
|
@property (nonatomic ,strong) VideoTabPopView *popView;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation MyTabBarViewController
|
|
|
|
|
|
|
|
-(void)removeTransitionImageView{
|
|
|
|
if(_TransitionImageView){
|
|
|
|
// xLog(@"开始-0----------");
|
|
|
|
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
|
|
|
|
_TransitionImageView.alpha = 0.0f;
|
|
|
|
} completion:^(BOOL finished) {
|
|
|
|
if(finished){
|
|
|
|
// xLog(@"结束-----------finished:%d",finished);
|
|
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
|
[_TransitionImageView removeFromSuperview];
|
|
|
|
_TransitionImageView = nil;
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
|
|
|
[self addNotification];
|
|
|
|
// WEAKSELF
|
|
|
|
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
|
// NSMutableArray* arr = [NSMutableArray arrayWithArray: weakSelf.viewControllers];
|
|
|
|
// [arr removeObjectAtIndex:1];
|
|
|
|
// [weakSelf setViewControllers:arr];
|
|
|
|
// });
|
|
|
|
if(!cUser){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[self.tabBar setBackgroundImage:[UIImage new]];
|
|
|
|
[self.tabBar setShadowImage:[UIImage new]];
|
|
|
|
|
|
|
|
|
|
|
|
if (@available(iOS 15.0, *))
|
|
|
|
{
|
|
|
|
UITabBarAppearance *barAppearance = [[UITabBarAppearance alloc] init];
|
|
|
|
barAppearance.backgroundEffect = nil;
|
|
|
|
self.tabBar.scrollEdgeAppearance = barAppearance;
|
|
|
|
self.tabBar.standardAppearance = barAppearance;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Fallback on earlier versions
|
|
|
|
[UITabBar appearance].translucent = NO;
|
|
|
|
}
|
|
|
|
self.delegate = self;
|
|
|
|
[self addChildViewControllers];
|
|
|
|
[self addTabarItems];
|
|
|
|
self.popView = [[VideoTabPopView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
|
|
|
|
[self.view addSubview:self.popView];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)addChildViewControllers
|
|
|
|
{
|
|
|
|
|
|
|
|
ZXNavigationBarNavigationController *homeMsgVC = [[ZXNavigationBarNavigationController alloc] initWithRootViewController:[HomeMessageViewController new]];
|
|
|
|
|
|
|
|
ZXNavigationBarNavigationController *homeVC = [[ZXNavigationBarNavigationController alloc] initWithRootViewController:[WatchHomeViewController new]];
|
|
|
|
|
|
|
|
ZXNavigationBarNavigationController *videoVC = [[ZXNavigationBarNavigationController alloc] initWithRootViewController:[TabBarVideoViewController new]];
|
|
|
|
|
|
|
|
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
|
|
|
|
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"MapViewController"];
|
|
|
|
|
|
|
|
ZXNavigationBarNavigationController *mapVC = [[ZXNavigationBarNavigationController alloc] initWithRootViewController:vc];
|
|
|
|
|
|
|
|
ZXNavigationBarNavigationController *myVC = [[ZXNavigationBarNavigationController alloc] initWithRootViewController:[MyViewController new]];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.viewControllers = @[homeMsgVC, mapVC, videoVC, homeVC, myVC];
|
|
|
|
|
|
|
|
self.tabBar.tintColor = mainColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)addTabarItems
|
|
|
|
{
|
|
|
|
NSArray *titleNames = @[@"聊天",
|
|
|
|
@"定位",
|
|
|
|
@"",
|
|
|
|
@"守护",
|
|
|
|
@"我的"];
|
|
|
|
|
|
|
|
NSArray *normalImages = @[@"tab_message_nor",
|
|
|
|
@"tab_positioning_nor",
|
|
|
|
@"tab_call_icon",
|
|
|
|
@"tab_首页_nor",
|
|
|
|
@"tab_我的_nor"];
|
|
|
|
|
|
|
|
NSArray *selectedImages = @[@"tab_message_sel",
|
|
|
|
@"tab_positioning_sel",
|
|
|
|
@"tab_call_icon",
|
|
|
|
@"tab_首页_sel",
|
|
|
|
@"tab_我的_sel"];
|
|
|
|
|
|
|
|
|
|
|
|
//SNJJSELF
|
|
|
|
[self.childViewControllers enumerateObjectsUsingBlock:^(UIViewController *obj, NSUInteger idx, BOOL *stop) {
|
|
|
|
|
|
|
|
obj.tabBarItem.title = [titleNames objectAtIndex:idx];
|
|
|
|
obj.tabBarItem.image = [[UIImage imageNamed:normalImages[idx]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
|
|
|
obj.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImages[idx]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
self.tabBar.tintColor = mainColor;
|
|
|
|
if (@available(iOS 13.0, *))
|
|
|
|
{
|
|
|
|
self.tabBar.unselectedItemTintColor = RGB(98, 100, 102);
|
|
|
|
self.tabBar.tintColor = mainColor;
|
|
|
|
self.tabBar.backgroundColor = UIColor.whiteColor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self.tabBar.backgroundColor = UIColor.whiteColor;
|
|
|
|
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: RGB(98, 100, 102)} forState:UIControlStateNormal];
|
|
|
|
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: mainColor} forState:UIControlStateSelected];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)addNotification{
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserverForName:@"outLogin"
|
|
|
|
object:nil
|
|
|
|
queue:[NSOperationQueue mainQueue]
|
|
|
|
usingBlock:^(NSNotification * _Nonnull note)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!cUser){
|
|
|
|
//如果 outLogin 推送前 用户信息已经没有了,那么就是 token无效的场景,清除密码
|
|
|
|
[UserDefaults setBool:NO forKey:kifRememberPWDKey];
|
|
|
|
[UserDefaults removeObjectForKey:@"lastpwd"];
|
|
|
|
}
|
|
|
|
//清空推送角标
|
|
|
|
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
|
|
|
|
[User setCurrentUser:nil];
|
|
|
|
//如果有菊风设备的,退出菊风SDK的推送
|
|
|
|
[[JCManager shared] uninitialize];
|
|
|
|
//退出登录,清除每天第一次登陆的记录
|
|
|
|
[UserDefaults removeObjectForKey:FirstEveryDayKey];
|
|
|
|
[self goLoginVCWithAnimate:YES];
|
|
|
|
|
|
|
|
if (launchView) {
|
|
|
|
[UIView animateWithDuration:1.0f animations:^{
|
|
|
|
launchView.alpha = 0.0f;
|
|
|
|
} completion:^(BOOL finished) {
|
|
|
|
[launchView removeFromSuperview];
|
|
|
|
launchView = nil;
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserverForName:PUSH_type_chatGroupDisband
|
|
|
|
object:nil
|
|
|
|
queue:[NSOperationQueue mainQueue]
|
|
|
|
usingBlock:^(NSNotification * _Nonnull note)
|
|
|
|
{
|
|
|
|
if (!cUser) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ([cUser.openid isEqualToString:note.object[@"operator"]]) {
|
|
|
|
[UICommon MessageErrorText:@"该设备已经恢复出厂设置"];
|
|
|
|
|
|
|
|
[cUser localDeleteDevice];
|
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"lastLoginName"];
|
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
|
sleep(1);
|
|
|
|
|
|
|
|
|
|
|
|
[self goLoginVCWithAnimate:YES];
|
|
|
|
}else{
|
|
|
|
//如果是关注的设备,被管理员 恢复出厂设置了,需要清空一下聊天群,然后回到主页面重新 刷新数据
|
|
|
|
//清空 一下 聊天群组
|
|
|
|
cUser.chatGroups = nil;
|
|
|
|
[self setSelectedIndex:0];
|
|
|
|
UINavigationController *navVC = (UINavigationController*)self.selectedViewController;
|
|
|
|
[navVC popToRootViewControllerAnimated:YES];
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)goLoginVCWithAnimate:(BOOL)animate{
|
|
|
|
//清空通知栏消息
|
|
|
|
//要先把BadgeNumber 设成跟当前不同的值,然后再设成0,就欧了;
|
|
|
|
[UIApplication sharedApplication].applicationIconBadgeNumber = 1;
|
|
|
|
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
|
|
|
|
AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
|
|
|
[app showRootViewController];
|
|
|
|
|
|
|
|
// UIStoryboard *addDeviceSB = [UIStoryboard storyboardWithName:@"LoginStoryboard" bundle:nil];
|
|
|
|
// ZXNavigationBarNavigationController *vc = [addDeviceSB instantiateViewControllerWithIdentifier:@"LoginNav"];
|
|
|
|
// vc.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
|
|
// [self presentViewController:vc animated:animate completion:^{
|
|
|
|
// [self.viewControllers enumerateObjectsUsingBlock:^(__kindof UINavigationController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
|
// UIViewController *vc = [obj.viewControllers firstObject];
|
|
|
|
// [vc.navigationController popToRootViewControllerAnimated:YES];
|
|
|
|
// }];
|
|
|
|
//
|
|
|
|
// if (self.selectedIndex != 0) {
|
|
|
|
// self.selectedIndex = 0;
|
|
|
|
// }
|
|
|
|
// }];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
|
|
|
|
UINavigationController *selectNav = (UINavigationController*)viewController;
|
|
|
|
if ((cUser.myDevices.count == 0 && [NSStringFromClass([selectNav.topViewController class]) isEqualToString:@"MapViewController"]) ||
|
|
|
|
(cUser.myDevices.count == 0 && [NSStringFromClass([selectNav.topViewController class]) isEqualToString:@"TabBarVideoViewController"]))
|
|
|
|
{
|
|
|
|
//要跳 定位页面
|
|
|
|
WEAKSELF
|
|
|
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"绑定设备" message:@"未绑定设备,是否前往绑定?" style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:@"取消" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) {
|
|
|
|
|
|
|
|
// add by lsz 2020-07-13
|
|
|
|
weakSelf.selectedIndex = 3;
|
|
|
|
|
|
|
|
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"LoginStoryboard" bundle:nil];
|
|
|
|
UINavigationController *vc = [sb instantiateViewControllerWithIdentifier:@"ScanCodeViewController"];
|
|
|
|
UINavigationController *homeNav = (UINavigationController*)weakSelf.viewControllers.firstObject;
|
|
|
|
//获取 首页的 UINavigationController
|
|
|
|
[homeNav pushViewController:vc animated:YES];
|
|
|
|
|
|
|
|
} cancelHandler:nil destructiveHandler:nil];
|
|
|
|
[alertView showAnimated:YES completionHandler:nil];
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
if ([NSStringFromClass([selectNav.topViewController class]) isEqualToString:@"TabBarVideoViewController"])
|
|
|
|
{
|
|
|
|
NSLog(@"点击拨打视频电话");
|
|
|
|
|
|
|
|
[self.popView showView];
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
- (void)didReceiveMemoryWarning {
|
|
|
|
[super didReceiveMemoryWarning];
|
|
|
|
// Dispose of any resources that can be recreated.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (BOOL)shouldAutorotate
|
|
|
|
{
|
|
|
|
return [self.selectedViewController shouldAutorotate];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
|
|
|
|
{
|
|
|
|
return [self.selectedViewController supportedInterfaceOrientations];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
|
|
|
|
{
|
|
|
|
return [self.selectedViewController preferredInterfaceOrientationForPresentation];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void)load
|
|
|
|
{
|
|
|
|
// 获取当前类的tabBarItem
|
|
|
|
UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
|
|
|
|
NSMutableDictionary *attrnor = [NSMutableDictionary dictionary];
|
|
|
|
attrnor[NSFontAttributeName] = [UIFont systemFontOfSize:11];
|
|
|
|
[item setTitleTextAttributes:attrnor forState:UIControlStateNormal];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void)initialize
|
|
|
|
{
|
|
|
|
//Tabbar不透明
|
|
|
|
[UITabBar appearance].translucent = NO;
|
|
|
|
//Tabbar黑色
|
|
|
|
[UITabBar appearance].backgroundImage = [self imageWithColor:UIColor.whiteColor];
|
|
|
|
//隐藏Tabbar分割线
|
|
|
|
UIImage *clearImage = [self imageWithColor:UIColor.whiteColor];
|
|
|
|
[[UITabBar appearance] setShadowImage:clearImage];
|
|
|
|
//TableView适配
|
|
|
|
[UITableView appearance].estimatedRowHeight = 0;
|
|
|
|
[UITableView appearance].estimatedSectionHeaderHeight = 0;
|
|
|
|
[UITableView appearance].estimatedSectionFooterHeight = 0;
|
|
|
|
//ScrollView适配
|
|
|
|
if (@available(iOS 11.0, *)){
|
|
|
|
[[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ (UIImage*)imageWithColor:(UIColor*)color
|
|
|
|
{
|
|
|
|
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
|
|
|
|
UIGraphicsBeginImageContext(rect.size);
|
|
|
|
CGContextRef context = UIGraphicsGetCurrentContext();
|
|
|
|
|
|
|
|
CGContextSetFillColorWithColor(context, [color CGColor]);
|
|
|
|
CGContextFillRect(context, rect);
|
|
|
|
|
|
|
|
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
|
|
|
|
UIGraphicsEndImageContext();
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
//实现中间按钮放大的关键代码
|
|
|
|
- (void)viewWillLayoutSubviews
|
|
|
|
{
|
|
|
|
for (int i = 0; i<self.tabBar.items.count; i ++)
|
|
|
|
{
|
|
|
|
UITabBarItem *itm = self.tabBar.items[i];
|
|
|
|
if (i == 2)
|
|
|
|
{
|
|
|
|
itm.imageInsets = UIEdgeInsetsMake(0, -5, -7, -5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
-(UITabBarItem*)generateTabBarItem:(NSString*)title imgName:(NSString*)imgName selectedImgName:(NSString*)selectedImgName
|
|
|
|
{
|
|
|
|
UIImage *img = [[UIImage imageNamed:imgName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
|
|
|
UIImage *selectedImg = [[UIImage imageNamed:selectedImgName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
|
|
|
return [[UITabBarItem alloc] initWithTitle:title image:img selectedImage:selectedImg];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@end
|