RootTabBarController.m
6.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//
// 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