CNLiveBaseViewController.m
7.74 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
190
191
192
193
194
//
// CNLiveBaseViewController.m
// CNLiveScioLive
//
// Created by CNLive-zxw on 2018/9/17.
// Copyright © 2018年 CNLive. All rights reserved.
//
#import "CNLiveBaseViewController.h"
@interface CNLiveBaseViewController ()
@property (strong, nonatomic, readwrite) AppDelegate *appDelegate;
@property (weak, nonatomic) UIButton *headerButton;
@end
@implementation CNLiveBaseViewController
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
NSNumber *orientationUnknown = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
[[UIDevice currentDevice] setValue:orientationUnknown forKey:@"orientation"];
NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationMaskPortrait];
[[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
// [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
[self setUpNavigationBar];
self.view.backgroundColor = [UIColor whiteColor];
// [self.navigationController setNavigationBarHidden:NO];
}
- (void)setName:(NSString *)name{
_name = name;
[_headerButton setTitle:name forState:UIControlStateNormal];
}
- (void)viewDidLoad {
[super viewDidLoad];
UITableView.appearance.estimatedRowHeight = 0;
UITableView.appearance.estimatedSectionFooterHeight = 0;
UITableView.appearance.estimatedSectionHeaderHeight = 0;
// Do any additional setup after loading the view.
}
#pragma mark - UI
- (void)setUpNavigationBar{
self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName:[UIFont systemFontOfSize:18]};
//左
UIButton *headerButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
headerButton.layer.cornerRadius = 2.0;
headerButton.layer.masksToBounds = true;
[headerButton setImage:[UIImage imageNamed:@"cnlive_icon"] forState:UIControlStateNormal];
[headerButton setImage:[UIImage imageNamed:@"cnlive_icon"] forState:UIControlStateHighlighted];
[headerButton setImage:[UIImage imageNamed:@"cnlive_icon"] forState:UIControlStateSelected];
[headerButton setTitle:_name forState:UIControlStateNormal];
[headerButton setTitleColor:Color_Blue forState:UIControlStateNormal];
headerButton.titleLabel.font = [UIFont systemFontOfSize:15];
headerButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//居左显示
headerButton.titleEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 0);
_headerButton = headerButton;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:headerButton];
//右
UIButton *languageButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 23, 44)];
if(IS_CHINESE){
[languageButton setImage:[UIImage imageNamed:@"cnlive_EN"] forState:UIControlStateNormal];
[languageButton setImage:[UIImage imageNamed:@"cnlive_CN"] forState:UIControlStateSelected];
}else{
[languageButton setImage:[UIImage imageNamed:@"cnlive_CN"] forState:UIControlStateNormal];
[languageButton setImage:[UIImage imageNamed:@"cnlive_EN"] forState:UIControlStateSelected];
}
[languageButton addTarget:self action:@selector(chinaENLanguageSwitch:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithCustomView:languageButton];
self.navigationItem.rightBarButtonItem = item2;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#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.
}
*/
#pragma mark - Action
//中英文切换
- (void)chinaENLanguageSwitch:(UIButton *)btn{
NSString *title = IS_CHINESE?@"Switch To English?":@"切换到中文版本?";
NSString *subTitle = IS_CHINESE?@"切换到英文版本?":@"Switch To Chinese?";
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:subTitle preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"切换 Switch" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了确定,进入确定的事件");
btn.selected = !btn.selected;
self->_appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
//本地存储语言版本
if (IS_CHINESE) {
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"en", nil] forKey:@"AppleLanguages"];
[User_Defaults setObject:@"en" forKey:Language_Local];
self->_appDelegate.lan = @"en";
[User_Defaults synchronize];
}else{
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"zh-Hans", nil] forKey:@"AppleLanguages"];
[User_Defaults setObject:@"zh-Hans" forKey:Language_Local];
self->_appDelegate.lan =@"zh-Hans";
[User_Defaults synchronize];
}
[(AppDelegate *)[UIApplication sharedApplication].delegate initializeSDKConfiguration];
// if([[ZXWUserInformation shareZXWUserInformation] isLogin]){
// [[ZXWUserInformation shareZXWUserInformation] loginOut];
// // 取消第三方平台授权
// [ShareSDK cancelAuthorize:SSDKPlatformTypeWechat];
// [ShareSDK cancelAuthorize:SSDKPlatformTypeQQ];
// [ShareSDK cancelAuthorize:SSDKPlatformTypeSinaWeibo];
// }
//切换RootViewController
if(IS_CHINESE){
CNLiveTabBarController *liveTab = [[CNLiveTabBarController alloc] init];
XLSlideMenu *slideMenu = [[XLSlideMenu alloc] initWithRootViewController:liveTab];
//设置左右菜单
slideMenu.slideEnabled = NO;
CNHomeRightViewController *rightVC = [[CNHomeRightViewController alloc]init];
rightVC.block = ^(NSInteger row) {
CNHomeViewController *vc = (CNHomeViewController *)liveTab.viewControllers[0];
vc.segmentControl.current = row;
};
slideMenu.rightViewController = rightVC;
[UIApplication sharedApplication].keyWindow.rootViewController = slideMenu;
}else{
CNLiveENTabBarController *liveTab = [[CNLiveENTabBarController alloc] init];
[UIApplication sharedApplication].keyWindow.rootViewController = liveTab;
}
[[NSNotificationCenter defaultCenter] postNotificationName:@"changeLanguageVersion" object:nil];
}];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消 Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了取消");
}];
[alert addAction:action1];
[alert addAction:action2];
[self presentViewController:alert animated:YES completion:nil];
}
- (void)goBack {
if(self.navigationController.viewControllers.count > 0){
[self.navigationController popViewControllerAnimated:YES];
}else{
[self dismissViewControllerAnimated:YES completion:nil];
}
}
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDefault;
}
@end