347 lines
11 KiB
Objective-C
347 lines
11 KiB
Objective-C
//
|
|
// IfishMianTabViewController.m
|
|
// ifishTabTest
|
|
//
|
|
// Created by imac on 16/7/25.
|
|
// Copyright © 2016年 xiang. All rights reserved.
|
|
//
|
|
|
|
#import "IfishMianTabViewController.h"
|
|
#import "AppDelegate.h"
|
|
#import "UINavigationBar+Background.h"
|
|
#import "IfishStartAdView.h"
|
|
#import "IfishUserDefaultHelper.h"
|
|
#import "IfishUserObsever.h"
|
|
#import "UITabBar+addRedPointBadge.h"
|
|
#import "LoveFishLiveListBaseViewController.h"
|
|
#import "UIViewController+Navgation.h"
|
|
@interface IfishMianTabViewController ()<UITabBarControllerDelegate,HomeStartAdviewDelegate>
|
|
|
|
@property (nonatomic,strong) NSArray *navigationHandlers;
|
|
@property (nonatomic,assign) NSInteger sessionUnreadCount;
|
|
@property (nonatomic,assign) NSInteger systemUnreadCount;
|
|
@property (nonatomic,assign) NSInteger customSystemUnreadCount;
|
|
@property (nonatomic,copy) NSDictionary *configs;
|
|
@property (nonatomic,strong) UINavigationController *meassageNavVC;
|
|
|
|
@end
|
|
|
|
extern BOOL launchedByNotification;
|
|
@implementation IfishMianTabViewController
|
|
|
|
+ (instancetype)instance{
|
|
AppDelegate *delegete = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
|
UIViewController *vc = delegete.window.rootViewController;
|
|
if ([vc isKindOfClass:[IfishMianTabViewController class]]) {
|
|
return (IfishMianTabViewController *)vc;
|
|
|
|
}else{
|
|
return nil;
|
|
}
|
|
}
|
|
|
|
-(instancetype)init{
|
|
self = [super init];
|
|
if (self) {
|
|
[self creatViewControllers];
|
|
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
// Do any additional setup after loading the view.
|
|
//[self creatViewControllers];
|
|
//[self setUpSubNav];
|
|
|
|
self.tabBar.translucent = NO;
|
|
static dispatch_once_t disOnceAdview;
|
|
dispatch_once(&disOnceAdview, ^ {
|
|
BOOL show = [IfishUserDefaultHelper digShowAdview];
|
|
if (show) {
|
|
return ;
|
|
}
|
|
//首页弹窗
|
|
//[self showAdview];
|
|
|
|
});
|
|
|
|
|
|
}
|
|
-(void)showAdview{
|
|
|
|
IfishStartAdView *adview=[[IfishStartAdView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
|
|
adview.delegate = self;
|
|
[self.view addSubview:adview];
|
|
|
|
}
|
|
|
|
#pragma mark- HomeStartAdviewDelegate
|
|
|
|
-(void)goButtonAction{
|
|
|
|
[IfishUserDefaultHelper showAdview:YES];
|
|
[self setSelectedIndex:2];
|
|
[self performSelector:@selector(homeAdViewAction) withObject:self afterDelay:1];
|
|
|
|
}
|
|
|
|
-(void)homeAdViewAction
|
|
{
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"homeAdViewAction" object:nil];
|
|
|
|
}
|
|
|
|
|
|
- (void)didReceiveMemoryWarning {
|
|
[super didReceiveMemoryWarning];
|
|
// Dispose of any resources that can be recreated.
|
|
}
|
|
-(void)creatViewControllers{
|
|
|
|
// 新v4.3前 消息在tab栏上
|
|
//NSArray*VCArr=@[@"IfishDeviceViewController",
|
|
// @"IfishDiscoverViewController",
|
|
// @"IfishMeViewController"];
|
|
//消息在首页导航上
|
|
NSArray*VCArr=@[@"IfishDeviceViewController",
|
|
@"LoveFishLiveListBaseViewController",
|
|
@"IfishDiscoverViewController",
|
|
@"IfishMeViewController"];
|
|
|
|
NSArray *titles=@[@"首页",@"爱鱼看看",@"探索",@"我的"];
|
|
NSArray *ImageArr=@[@"ifish_facility_off",
|
|
@"ifish_look_off",
|
|
@"ifish_discovery_off",
|
|
@"ifish_me_off"];
|
|
|
|
NSArray *selectImageArr=@[@"ifish_facility_on",
|
|
@"ifish_look_on",
|
|
@"ifish_discovery_on",
|
|
@"ifish_me_on"];
|
|
|
|
NSMutableArray *VCArr1=[[NSMutableArray alloc]init];
|
|
for (NSInteger i=0; i<VCArr.count; i++) {
|
|
NSString *VCName=VCArr[i];
|
|
Class cls=NSClassFromString(VCName);
|
|
UIViewController *vc=[[cls alloc]init];
|
|
|
|
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:vc];
|
|
|
|
//只改变导航栏不改变状态栏 切要加上下面一句才会明显改变颜色 不然颜色会被遮挡
|
|
//nav.navigationBar.backgroundColor = [UIColor redColor];
|
|
//[nav.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
|
|
//直接切图 或扩展导航UINavigationBar+Background
|
|
[nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]];
|
|
|
|
NSString *title=titles[i];
|
|
vc.title = title;
|
|
|
|
//返回按钮图片和字体颜色
|
|
nav.navigationBar.tintColor= [UIColor whiteColor];
|
|
[nav.navigationBar setTitleTextAttributes:
|
|
|
|
@{NSFontAttributeName:[UIFont systemFontOfSize:19],
|
|
|
|
NSForegroundColorAttributeName:[UIColor whiteColor]}];
|
|
[nav setNavTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],
|
|
|
|
NSForegroundColorAttributeName:[UIColor whiteColor]}];
|
|
//IOS7后本项目可不做IOS7 以下处理
|
|
UIImage *imgnomal=[UIImage imageNamed:ImageArr[i]];
|
|
|
|
UIImage *imgSelct=[UIImage imageNamed:selectImageArr[i]];
|
|
|
|
nav.tabBarItem.image=[imgnomal imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
|
nav.tabBarItem.selectedImage = [imgSelct imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
|
|
|
[nav.tabBarItem setTitleTextAttributes: @{
|
|
|
|
NSForegroundColorAttributeName:TABLE_BAR_SELCTNAMECOLOR} forState:UIControlStateSelected];
|
|
|
|
//消息在tab栏打开
|
|
/*if (i==1) {
|
|
|
|
NSInteger count = [[[NIMSDK sharedSDK] conversationManager] allUnreadCount];
|
|
if (count !=0) {
|
|
|
|
nav.tabBarItem.badgeValue = [NSString stringWithFormat:@"%ld",(long)count];
|
|
}else{
|
|
nav.tabBarItem.badgeValue =nil;
|
|
}
|
|
self.meassageNavVC = nav;
|
|
|
|
}*/
|
|
|
|
if (i==3) {
|
|
|
|
//NSInteger undoneCount = [IfishHelperUtils getUnDoneTaskCount];
|
|
|
|
[self.tabBar showBadgeOnItemIndex:3];
|
|
}
|
|
[VCArr1 addObject:nav];
|
|
}
|
|
self.tabBar.backgroundColor=[UIColor whiteColor];
|
|
self.viewControllers=VCArr1;
|
|
|
|
if (launchedByNotification) {
|
|
//点击通知栏启动应用 原消息在tab1 现改为0 如以后要点击通知栏在tab展示消息 或跳转相应tab 在此处理
|
|
self.selectedIndex = 0;
|
|
launchedByNotification = NO;
|
|
|
|
}else{
|
|
self.selectedIndex = 0;
|
|
}
|
|
|
|
// 任务badge
|
|
[[NSNotificationCenter defaultCenter] addObserverForName:IFISHTASK_HAVEDONEALL object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
|
|
[self.tabBar hideBadgeOnItemIndex:3];
|
|
}];
|
|
}
|
|
|
|
-(void)viewWillAppear:(BOOL)animated{
|
|
[super viewWillAppear:animated];
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(presentMassageView) name:@"PresentView" object:nil];
|
|
|
|
[[Socketsingleton sharedInstance] cutOffSocket];
|
|
|
|
/* //后台未挂起 点击icon进入
|
|
NSInteger count = [[[NIMSDK sharedSDK] conversationManager] allUnreadCount];
|
|
//count ==0 ? (self.meassageNavVC.tabBarItem.badgeValue =nil):(self.meassageNavVC.tabBarItem.badgeValue = [NSString stringWithFormat:@"%ld",(long)count]);
|
|
|
|
count ==0 ? (self.viewControllers[1].tabBarItem.badgeValue =nil):(self.viewControllers[1].tabBarItem.badgeValue = [NSString stringWithFormat:@"%ld",(long)count]);*/
|
|
|
|
}
|
|
|
|
- (void)setUpStatusBar{
|
|
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
|
|
}
|
|
|
|
|
|
-(void)viewDidAppear:(BOOL)animated{
|
|
[super viewDidAppear:animated];
|
|
|
|
|
|
}
|
|
|
|
-(void)viewWillDisappear:(BOOL)animated{
|
|
|
|
[super viewWillDisappear:animated];
|
|
|
|
}
|
|
|
|
-(void)viewDidDisappear:(BOOL)animated{
|
|
[super viewDidDisappear:animated];
|
|
|
|
|
|
}
|
|
|
|
-(void)presentMassageView{
|
|
|
|
self.selectedIndex = 1;
|
|
|
|
}
|
|
|
|
|
|
- (void)allMessagesDeleted{
|
|
self.sessionUnreadCount = 0;
|
|
}
|
|
|
|
#pragma mark - NIMSystemNotificationManagerDelegate
|
|
- (void)onSystemNotificationCountChanged:(NSInteger)unreadCount
|
|
{
|
|
self.systemUnreadCount = unreadCount;
|
|
unreadCount ==0 ? (self.meassageNavVC.tabBarItem.badgeValue =nil):(self.meassageNavVC.tabBarItem.badgeValue = [NSString stringWithFormat:@"%ld",(long)unreadCount]);
|
|
|
|
|
|
}
|
|
|
|
|
|
- (UIStatusBarStyle)preferredStatusBarStyle {
|
|
return UIStatusBarStyleLightContent;
|
|
//return UIStatusBarStyleDefault;
|
|
}
|
|
|
|
#pragma mark - NTESNavigationGestureHandlerDataSource
|
|
- (UINavigationController *)navigationController
|
|
{
|
|
return self.selectedViewController;
|
|
}
|
|
|
|
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPushItem:(UINavigationItem *)item{
|
|
|
|
//UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
|
|
|
|
// item.backBarButtonItem = back;
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
#pragma mark - Rotate
|
|
|
|
//- (BOOL)shouldAutorotate{
|
|
// BOOL enableRotate = [NTESBundleSetting sharedConfig].enableRotate;
|
|
// return enableRotate ? [self.selectedViewController shouldAutorotate] : NO;
|
|
|
|
|
|
|
|
//}
|
|
|
|
//- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
|
|
// BOOL enableRotate = [NTESBundleSetting sharedConfig].enableRotate;
|
|
// return enableRotate ? [self.selectedViewController supportedInterfaceOrientations] : UIInterfaceOrientationMaskPortrait;
|
|
//}
|
|
|
|
|
|
|
|
#pragma mark - 屏幕Autorotate
|
|
-(BOOL)shouldAutorotate{
|
|
return YES;
|
|
}
|
|
|
|
#pragma mark 屏幕支持的旋转方向
|
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface {
|
|
return (interface == UIInterfaceOrientationPortrait || interface == UIInterfaceOrientationLandscapeRight);
|
|
}
|
|
//
|
|
#ifdef IOS6
|
|
|
|
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
|
|
{
|
|
return UIInterfaceOrientationLandscapeRight;
|
|
}
|
|
|
|
- (BOOL)shouldAutorotate {
|
|
return NO;
|
|
}
|
|
|
|
- (NSUInteger)supportedInterfaceOrientations {
|
|
return UIInterfaceOrientationMaskLandscapeRight;
|
|
}
|
|
#endif
|
|
//
|
|
#pragma mark 支持哪些方向
|
|
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
|
|
// if (_isCanAutoOrientation) {
|
|
return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscapeRight;
|
|
// }
|
|
|
|
//return UIInterfaceOrientationMaskPortrait;
|
|
}
|
|
|
|
#pragma mark 一开始希望的屏幕方向
|
|
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
|
|
return UIInterfaceOrientationPortrait;
|
|
}
|
|
|
|
|
|
#pragma mark - 屏幕旋转
|
|
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
|
|
{
|
|
|
|
}
|
|
|
|
@end
|