CNCommonViewController.m
5.49 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
//
// CNCommonViewController.m
// CNLiveNetAdd
//
// Created by 张旭 on 2017/12/30.
// Copyright © 2017年 cnlive. All rights reserved.
//
#import "CNCommonViewController.h"
#import <CNLiveRequestBastKit/CNLiveNetworking.h>
#import "QMUIKit.h"
#import "CNThemeManager.h"
@interface CNCommonViewController ()
@end
@implementation CNCommonViewController
#pragma mark - Life Cycle
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[UIView setAnimationsEnabled:YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self p_startNetworkMonitoring];
}
- (void)initSubviews {
[super initSubviews];
self.automaticallyAdjustsScrollViewInsets = NO;
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
}
#pragma mark - UI
- (void)setCNNoNetworkingEmptyView {
self.emptyView.backgroundColor = [UIColor whiteColor];
self.emptyView.actionButton.backgroundColor = UIColorMake(0, 194, 0);
self.emptyView.actionButton.layer.masksToBounds = YES;
self.emptyView.actionButton.layer.cornerRadius = 6;
self.emptyView.imageViewInsets = UIEdgeInsetsMake(0, 0, 15, 0);
self.emptyView.textLabelInsets = UIEdgeInsetsMake(0, 0, 14, 0);
self.emptyView.detailTextLabelInsets = UIEdgeInsetsMake(0, 0, 16, 0);
[self.emptyView setTextLabelFont:UIFontMake(17)];
[self.emptyView setDetailTextLabelFont:UIFontMake(13)];
[self.emptyView setTextLabelTextColor:UIColorMake(102, 102, 102)];
[self.emptyView setDetailTextLabelTextColor:UIColorMake(153, 153, 153)];
}
- (void)setCNAPIErrorEmptyView {
self.emptyView.actionButton.backgroundColor = UIColorMake(0, 194, 0);
self.emptyView.actionButton.layer.masksToBounds = YES;
self.emptyView.actionButton.layer.cornerRadius = 6;
self.emptyView.imageViewInsets = UIEdgeInsetsMake(0, 0, 15, 0);
self.emptyView.textLabelInsets = UIEdgeInsetsMake(0, 0, 14, 0);
self.emptyView.detailTextLabelInsets = UIEdgeInsetsMake(0, 0, 16, 0);
[self.emptyView setTextLabelFont:UIFontMake(17)];
[self.emptyView setDetailTextLabelFont:UIFontMake(13)];
[self.emptyView setTextLabelTextColor:UIColorMake(102, 102, 102)];
[self.emptyView setDetailTextLabelTextColor:UIColorMake(153, 153, 153)];
}
- (void)setCNNoDataEmptyView {
[self.emptyView setTextLabelFont:UIFontMake(17)];
[self.emptyView setTextLabelTextColor:UIColorMake(102, 102, 102)];
self.emptyView.imageViewInsets = UIEdgeInsetsMake(0, 0, 36, 0);
}
#pragma mark - Network Monitoring
- (void)p_startNetworkMonitoring {
__weak typeof(self) weakSelf = self;
[CNLiveNetworking networkStatusWithBlock:^(CNLiveNetworkStatusType status) {
if (status == CNLiveNetworkStatusUnknown || status == CNLiveNetworkStatusNotReachable) {
weakSelf.netStatus = status;
[weakSelf cn_noNetworking];//没网
}else
{//有网
weakSelf.netStatus = status;
[weakSelf cn_wifiOrWWANNetworking];
}
}];
// AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
// [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
// if (status == AFNetworkReachabilityStatusUnknown || status == AFNetworkReachabilityStatusNotReachable) {
// weakSelf.netStatus = status;
// [weakSelf cn_noNetworking];//没网
// }else
// {//有网
// weakSelf.netStatus = status;
// [weakSelf cn_wifiOrWWANNetworking];
// }
// }];
// [manager startMonitoring];
}
- (void)cn_noNetworking {//子类重写
}
- (void)cn_wifiOrWWANNetworking {//子类重写
}
- (void)didInitialize {
[super didInitialize];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleThemeChangedNotification:) name:CNThemeChangedNotification object:nil];
}
- (void)handleThemeChangedNotification:(NSNotification *)notification {
NSObject<CNThemeProtocol> *themeBeforeChanged = notification.userInfo[CNThemeBeforeChangedName];
NSObject<CNThemeProtocol> *themeAfterChanged = notification.userInfo[CNThemeAfterChangedName];
[self themeBeforeChanged:themeBeforeChanged afterChanged:themeAfterChanged];
}
#pragma mark - Navigation Delegate
- (UIImage *)navigationBarBackgroundImage {
return [self imageWithColor:[UIColor whiteColor]];
}
- (UIImage *)imageWithColor:(UIColor *)color {
return [self imageWithColor:color size:CGSizeMake(1, 1)];
}
- (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size {
if (color == nil) {
return nil;
}
CGRect rect=CGRectMake(0.0f, 0.0f, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
#pragma mark - System Delegate
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientationMask)supportedOrientationMask {
return UIInterfaceOrientationMaskPortrait;
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDefault;
}
- (BOOL)forceEnableInteractivePopGestureRecognizer {
return YES;
}
#pragma mark - CNChangingThemeDelegate
- (void)themeBeforeChanged:(NSObject<CNThemeProtocol> *)themeBeforeChanged afterChanged:(NSObject<CNThemeProtocol> *)themeAfterChanged {
}
@end