RootTabBarController.m 6.61 KB
//
//  RootTabBarController.m
//  IVTMeLiveTwo
//
//  Created by XRG on 16/8/10.
//  Copyright © 2016年 QLQ. All rights reserved.
//

#import "RootTabBarController.h"
#import "IVTGreatHallViewController.h"
#import "IVTLivePreviewViewController.h"
#import "IVTMyCenterViewController.h"
#import "BaseNavigationController.h"
#import "AppDelegate.h"
#import "IVTLoginViewController.h"
#import "GuideView.h"
#import "ADView.h"


@interface RootTabBarController ()<UITabBarControllerDelegate,UINavigationControllerDelegate>
{
    UIViewController *tempVC;
    
    UIView *globalMsgView;
    
    BOOL isShowADAndGuide;
}
@end

@implementation RootTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.delegate = self;
    
    IVTGreatHallViewController *greatHallVC = [[IVTGreatHallViewController alloc]init];
    tempVC = [[UIViewController alloc]init];
    IVTMyCenterViewController *myCenterVC = [[IVTMyCenterViewController alloc]init];
    NSArray *viewControllers = [NSArray arrayWithObjects:greatHallVC,tempVC,myCenterVC, nil];
    
    NSArray *tabBarTitleArray = [NSArray arrayWithObjects:@"大厅",@"直播",@"我的", nil];
    NSArray *tabBarImageNormalArray = [NSArray arrayWithObjects:@"大厅图标",@"直播点击按钮",@"我的图标", nil];
    NSArray *tabBarImageSelectArray = [NSArray arrayWithObjects:@"大厅图标-选中",@"直播点击按钮",@"我的图标--选中", nil];
    
    NSMutableArray *navs = [NSMutableArray arrayWithCapacity:3];
    for (NSInteger i=0; i<viewControllers.count; i++) {
        if (i == 1) {
            [tempVC.tabBarItem setImage:[[UIImage imageNamed:tabBarImageNormalArray[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
            [navs addObject:tempVC];
        }
        else{
            BaseNavigationController *nav = [[BaseNavigationController alloc]initWithRootViewController:viewControllers[i]];
            NSLog(@"*****=%p",nav);
            nav.delegate = self;
            nav.tabBarItem.title = tabBarTitleArray[i];
            [nav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColorFromRGBAlphaHex(0xD31863, 1.0)} forState:UIControlStateSelected];
            [nav.tabBarItem setImage:[[UIImage imageNamed:tabBarImageNormalArray[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
            [nav.tabBarItem setSelectedImage:[[UIImage imageNamed:tabBarImageSelectArray[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
            [navs addObject:nav];
        }
    }
    self.viewControllers = navs;
    
    [self.tabBar setBackgroundImage:[UIImage createImageInRect:CGRectMake(0, 0, kScreenWidth, 49) withColor:UIColorFromRGBAlphaHex(0xffffff, 1.0)]];
    [self.tabBar setShadowImage:[UIImage createImageInRect:CGRectMake(0, 0, kScreenWidth, 49) withColor:[UIColor clearColor]]];
    
    if ([IVTAccountTool isHaveUserLogin]) {
        [[IVTNetworkAPIClient sharedClient] autoLoginWithPhone];
        [[XMPPManager sharedInstance] loginWithUserId:[IVTAccountTool getUserId] pwd:[IVTAccountTool getPassword]];
    }
    
}


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    if (!isShowADAndGuide) {
        UIWindow *window = [AppDelegate appDelegate].window;
        BOOL isShowedGuide = [[NSUserDefaults standardUserDefaults] boolForKey:kIsShowedGuideLaunchedView];//存储的引导页id
        if (!isShowedGuide) {
            GuideView *guideView = [GuideView sharedInstance];
            [window addSubview:guideView];
        }
        
        ADView *adView = [ADView sharedInstance];
        [window addSubview:adView];

        isShowADAndGuide = YES;
    }
    
    if (self.isBinding) {
        return;
    }
    
    if (![IVTAccountTool isHaveUserLogin]) {
        IVTLoginViewController *loginVC = [[IVTLoginViewController alloc]init];
        [self presentViewController:loginVC animated:NO completion:^{
        }];
    }
}


- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    if ([viewController isEqual:tempVC]) {
        IVTLivePreviewViewController *livePVC = [[IVTLivePreviewViewController alloc]init];
        BaseNavigationController *nav = [[BaseNavigationController alloc]initWithRootViewController:livePVC];
        [AppDelegate appDelegate].livePreviewVC = livePVC;
//        self.modalPresentationStyle = UIModalPresentationFullScreen;
        [tempVC presentViewController:nav animated:YES completion:^{
            
        }];
        return NO;
    }
    return YES;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

+ (RootTabBarController *)tabBarVC {
    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    return (RootTabBarController *)appDelegate.window.rootViewController;
}

- (void)showGlobalMsg:(NSString *)msg {
    if (globalMsgView.superview) {
        [globalMsgView removeFromSuperview];
    }
    CGFloat x = 20, y = 10;
    CGFloat w = self.view.frame.size.width-40, h = 0;
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
    label.textAlignment = NSTextAlignmentCenter;
    label.numberOfLines = 0;
    label.font = [UIFont systemFontOfSize:15];
    label.textColor = [UIColor whiteColor];
    label.text = msg;
    [label sizeToFit];
    
    w = self.view.frame.size.width, h = label.frame.size.height+20;
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, w, h)];
    bgView.backgroundColor = UIColorFromRGBAlphaHex(0xE96B67, 0.9);
    [bgView addSubview:label];
    [self.view addSubview:bgView];
    [self.view bringSubviewToFront:bgView];
    bgView.hidden = YES;
    
    globalMsgView = bgView;
    
    [UIView animateWithDuration:0.5 animations:^{
        bgView.hidden = NO;
    }];
    
    [self performSelector:@selector(hideGlobalMsg:) withObject:bgView afterDelay:10];
}

- (void)hideGlobalMsg:(UIView *)view {
    [UIView animateWithDuration:0.5 animations:^{
        globalMsgView.hidden = YES;
    } completion:^(BOOL finished) {
        [globalMsgView removeFromSuperview];
    }];

}

//+

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end