xn_base_BaseViewController.m
6.28 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
//
// xn_base_BaseViewController.m
// xn_base_ios
//
// Created by 钱鋆 on 15/12/16.
// Copyright © 2015年 xn. All rights reserved.
//
#import "xn_base_BaseViewController.h"
#import <AudioToolbox/AudioToolbox.h>
@interface xn_base_BaseViewController (){
CGFloat _viewHeight;
BOOL isHotspot;
}
@end
@implementation xn_base_BaseViewController
@synthesize organizationId;
@synthesize mainLayout;
#pragma mark 创建单例
/**
* @author qianjun
*
* @brief 创建单例
*
* @return self
*/
+ (instancetype)sharedInstance {
static id sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
- (void)viewWillLayoutSubviews{
[super viewWillLayoutSubviews];
for (UIView *child in self.tabBarController.tabBar.subviews) {
if ([child isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
[child removeFromSuperview];
}
}
// if([[CommFun sharedInstance] f_flagWithOpenHotSpot]){
// if (!isHotspot) {
// self.mainLayout.frame = CGRectMake(self.mainLayout.frame.origin.x, self.mainLayout.frame.origin.y+20, self.mainLayout.frame.size.width, self.mainLayout.frame.size.height+20);
// isHotspot = YES;
// } else {
// isHotspot = NO;
// }
// }
}
#pragma mark dealloc
- (void)dealloc
{
// 删除AF返回的通知
// [[NSNotificationCenter defaultCenter] removeObserver:self name:kResponseNotiName object:nil];
}
#pragma mark 导航存在情况下的返回事件
/**
* @author qianjun
*
* @brief 导航存在情况下的返回事件
*/
-(void)f_backAction
{
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - 移除HUD
/**
* @author qianjun
*
* @brief 移除HUD
*/
-(void)f_HUD_remove
{
// if (HUD) {
// [self f_HUD_hide];
// if (HUD) {
// [HUD removeFromSuperview];
// }
// HUD = nil;
// }
}
#pragma mark 创建HUD
/**
* @author qianjun
*
* @brief 创建HUD
*/
-(void)f_HUD_create
{
// [self f_HUD_remove];
// 加载数据
// HUD = [[MBProgressHUD alloc] initWithView:self.mainLayout];
// [self.mainLayout addSubview:HUD];
// HUD = [[MBProgressHUD alloc] initWithWindow:[[[UIApplication sharedApplication] delegate] window]];
// [[[[UIApplication sharedApplication] delegate] window] addSubview:HUD];
// HUD.mode = MBProgressHUDModeIndeterminate;
}
#pragma mark 显示HUD
/**
* @author qianjun
*
* @brief 显示HUD
*/
-(void)f_HUD_show
{
dispatch_async(dispatch_get_main_queue(), ^{
// [self l_creatHUD];
// [self->HUD show:YES];
// [self->HUD.superview bringSubviewToFront:self->HUD];
});
}
#pragma mark 隐藏HUD
/**
* @author qianjun
*
* @brief 隐藏HUD
*/
-(void)f_HUD_hide
{
dispatch_async(dispatch_get_main_queue(), ^{
// [self->HUD hide:YES];
});
}
#pragma mark UIViewController Delegate
- (void)viewDidLoad {
[super viewDidLoad];
self.modalPresentationStyle = UIModalPresentationFullScreen;
// 隐藏导航栏底部黑线
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
// [self.view setBackgroundColor:COLOR_C_background];
mainLayout = [[UIView alloc]init];
// [mainLayout setBackgroundColor:COLOR_C_background];
[self.view addSubview:mainLayout];
[mainLayout mas_makeConstraints:^(MASConstraintMaker *make) {
if (@available(iOS 11.0, *)) {
make.edges.equalTo(self.view);
} else {
make.edges.equalTo(self.view);
}
}];
// 部分页面直接读取了mainLayout的size来设定子控件,这里需要立即获取控件大小
[self.view layoutIfNeeded];
//[self f_HUD_create];
}
-(void)f_resetSafeArea
{
[mainLayout mas_makeConstraints:^(MASConstraintMaker *make) {
if (@available(iOS 11.0, *)) {
make.edges.equalTo(self.view);
} else {
make.edges.equalTo(self.view);
}
}];
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// NSLog(@"%@, %@", self, self.view);
for (UIView *child in self.tabBarController.tabBar.subviews) {
if ([child isKindOfClass:[UIControl class]]) {
[child removeFromSuperview];
}
}
// self.edgesForExtendedLayout = UIRectEdgeNone;
}
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleDefault;
//UIStatusBarStyleDefault = 0 黑色文字,浅色背景时使用
//UIStatusBarStyleLightContent = 1 白色文字,深色背景时使用
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
-(void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (void)l_foregroundTask:(NSDictionary *)userInfo
{
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark 网络请求的回调
/**
* @author qianjun
*
* @brief 网络请求的回调
*
* @param noti 通知对象
*/
-(void)l_responseNoti:(NSNotification *)noti
{
if (_sel_clientResponse) {
[self performSelectorInBackground:_sel_clientResponse withObject:noti];
}
}
-(float)mStatusbarHeight{
//状态栏高度
return [[UIApplication sharedApplication] statusBarFrame].size.height;
}
-(float)mNavigationbarHeight{
//导航栏高度+状态栏高度
return self.navigationController.navigationBar.frame.size.height + [[UIApplication sharedApplication] statusBarFrame].size.height;
}
-(float)mTabbarHeight{
//Tabbar高度
return self.tabBarController.tabBar.bounds.size.height;
}
-(void)l_creatHUD{
// if (HUD == nil) {
// HUD = [[MBProgressHUD alloc]init];
// [self.mainLayout addSubview:HUD];
// }
// HUD.mode = MBProgressHUDModeIndeterminate;
}
-(void)l_writeLifeCycleLog:(NSString *)lifeCycle
{
// NSMutableDictionary *_dic = [[NSMutableDictionary alloc]init];
// [_dic setObject:NSStringFromClass([self class]) forKey:@"file_name"];
// [_dic setObject:lifeCycle forKey:@"method"];
// [[LoganHandler sharedInstance] wEvent:@"app.page.lifecycle" data:[[CommFun sharedInstance] f_toJSONString:_dic]];
}
@end