Commit 5b17c4a085fb8e6cdbd453d620c91118f281541f

Authored by zhangxiaowen
1 parent 47604c8d

no message

CNLiveQrCodeModule/Classes/Controller/CNLiveMyQrCodeController.m
@@ -125,6 +125,19 @@ static const CGFloat timeValue = 1.5; @@ -125,6 +125,19 @@ static const CGFloat timeValue = 1.5;
125 125
126 }]; 126 }];
127 } 127 }
  128 +// UIView转UIImage
  129 +- (UIImage *)generateImage:(UIView *)view{
  130 + // 1.开启上下文
  131 + UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, 0.0);
  132 + // 2. 将控制器View的Layer渲染到上下文
  133 + [view.layer renderInContext:UIGraphicsGetCurrentContext()];
  134 + // 3.取出图片
  135 + UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
  136 + // 4.结束上下文
  137 + UIGraphicsEndImageContext();
  138 +
  139 + return newImage;
  140 +}
128 141
129 #pragma mark - 代理 142 #pragma mark - 代理
130 143
@@ -150,8 +163,10 @@ static const CGFloat timeValue = 1.5; @@ -150,8 +163,10 @@ static const CGFloat timeValue = 1.5;
150 __strong typeof(weakSelf) strongSelf = weakSelf; 163 __strong typeof(weakSelf) strongSelf = weakSelf;
151 if(!strongSelf) return ; 164 if(!strongSelf) return ;
152 [strongSelf getPHAuthorizationStatus:^{ 165 [strongSelf getPHAuthorizationStatus:^{
153 - UIImage *image = [self.qrCodeView getImage]; 166 + UIImage *image = [strongSelf generateImage:strongSelf.qrCodeView];
  167 + [QMUITips showLoadingInView:strongSelf.view];
154 [strongSelf saveImage:image]; 168 [strongSelf saveImage:image];
  169 + [QMUITips hideAllTipsInView:strongSelf.view];
155 }]; 170 }];
156 self.navigationBar.right.userInteractionEnabled = YES; 171 self.navigationBar.right.userInteractionEnabled = YES;
157 172
CNLiveQrCodeModule/Classes/Controller/CNLiveScanQrCodeController.m
@@ -257,6 +257,7 @@ static const CGFloat timeValue = 1.5; @@ -257,6 +257,7 @@ static const CGFloat timeValue = 1.5;
257 return dic; 257 return dic;
258 } 258 }
259 259
  260 +#pragma mark - 代理
260 /** 261 /**
261 * 状态栏的颜色 262 * 状态栏的颜色
262 * 263 *
@@ -267,7 +268,7 @@ static const CGFloat timeValue = 1.5; @@ -267,7 +268,7 @@ static const CGFloat timeValue = 1.5;
267 return UIStatusBarStyleLightContent; 268 return UIStatusBarStyleLightContent;
268 269
269 } 270 }
270 -#pragma mark - 代理 271 +
271 - (void)navigationBar:(CNLiveQrCodeNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{ 272 - (void)navigationBar:(CNLiveQrCodeNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{
272 if ([actionEvents isEqualToString:@"1"]) { 273 if ([actionEvents isEqualToString:@"1"]) {
273 [self goBack]; 274 [self goBack];
CNLiveQrCodeModule/Classes/Controller/CNLiveScanResultController.m
@@ -48,6 +48,13 @@ @@ -48,6 +48,13 @@
48 [self.view addSubview:self.webView]; 48 [self.view addSubview:self.webView];
49 } 49 }
50 50
  51 +#pragma mark - 代理
  52 +- (void)navigationBar:(CNLiveQrCodeNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{
  53 + if ([actionEvents isEqualToString:@"1"]) {
  54 + [self goBack];
  55 + }
  56 +}
  57 +
51 - (void)webView:(CNLiveWebView *)webView didFinishLoadWithURL:(NSURL *)url { 58 - (void)webView:(CNLiveWebView *)webView didFinishLoadWithURL:(NSURL *)url {
52 NSLog(@"didFinishLoad"); 59 NSLog(@"didFinishLoad");
53 if(webView.navigationItemTitle.length != 0){ 60 if(webView.navigationItemTitle.length != 0){
@@ -58,12 +65,6 @@ @@ -58,12 +65,6 @@
58 } 65 }
59 66
60 } 67 }
61 -#pragma mark - 代理  
62 -- (void)navigationBar:(CNLiveQrCodeNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{  
63 - if ([actionEvents isEqualToString:@"1"]) {  
64 - [self goBack];  
65 - }  
66 -}  
67 68
68 - (void)webView:(CNLiveWebView *)webView didFailLoadWithError:(NSError *)error{ 69 - (void)webView:(CNLiveWebView *)webView didFailLoadWithError:(NSError *)error{
69 70
@@ -93,6 +94,7 @@ @@ -93,6 +94,7 @@
93 } 94 }
94 return _webView; 95 return _webView;
95 } 96 }
  97 +
96 #pragma mark - 响应方法 98 #pragma mark - 响应方法
97 - (void)goBack { 99 - (void)goBack {
98 if (self.presentingViewController != nil) { 100 if (self.presentingViewController != nil) {
CNLiveQrCodeModule/Classes/View/CNLiveMyQrCodeView.h
@@ -13,7 +13,6 @@ NS_ASSUME_NONNULL_BEGIN @@ -13,7 +13,6 @@ NS_ASSUME_NONNULL_BEGIN
13 @interface CNLiveMyQrCodeView : UIView 13 @interface CNLiveMyQrCodeView : UIView
14 14
15 - (void)generateQRCode:(NSString *)type; 15 - (void)generateQRCode:(NSString *)type;
16 -- (UIImage *)getImage;  
17 16
18 @end 17 @end
19 18
CNLiveQrCodeModule/Classes/View/CNLiveMyQrCodeView.m
@@ -139,10 +139,7 @@ static const CGFloat timeValue = 1.5; @@ -139,10 +139,7 @@ static const CGFloat timeValue = 1.5;
139 139
140 return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 140 return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
141 } 141 }
142 -// 保存图片  
143 -- (UIImage *)getImage{  
144 - return _qrCode.image;  
145 -} 142 +
146 /* 143 /*
147 // Only override drawRect: if you perform custom drawing. 144 // Only override drawRect: if you perform custom drawing.
148 // An empty implementation adversely affects performance during animation. 145 // An empty implementation adversely affects performance during animation.
CNLiveQrCodeModule/Classes/View/CNLiveWebView.m
@@ -59,7 +59,6 @@ static CGFloat const progressViewHeight = 2; @@ -59,7 +59,6 @@ static CGFloat const progressViewHeight = 2;
59 59
60 - (void)setProgressViewColor:(UIColor *)progressViewColor { 60 - (void)setProgressViewColor:(UIColor *)progressViewColor {
61 _progressViewColor = progressViewColor; 61 _progressViewColor = progressViewColor;
62 -  
63 if (progressViewColor) { 62 if (progressViewColor) {
64 _progressView.tintColor = progressViewColor; 63 _progressView.tintColor = progressViewColor;
65 } 64 }
@@ -74,7 +73,8 @@ static CGFloat const progressViewHeight = 2; @@ -74,7 +73,8 @@ static CGFloat const progressViewHeight = 2;
74 _progressView.frame = CGRectMake(0, 0, self.frame.size.width, progressViewHeight); 73 _progressView.frame = CGRectMake(0, 0, self.frame.size.width, progressViewHeight);
75 } 74 }
76 } 75 }
77 -/// KVO 76 +
  77 +// KVO
78 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context { 78 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
79 if ([keyPath isEqualToString:NSStringFromSelector(@selector(estimatedProgress))] && object == self.wkWebView) { 79 if ([keyPath isEqualToString:NSStringFromSelector(@selector(estimatedProgress))] && object == self.wkWebView) {
80 self.progressView.alpha = 1.0; 80 self.progressView.alpha = 1.0;
@@ -93,50 +93,47 @@ static CGFloat const progressViewHeight = 2; @@ -93,50 +93,47 @@ static CGFloat const progressViewHeight = 2;
93 } 93 }
94 94
95 #pragma mark - 加载的状态回调(WKNavigationDelegate) 95 #pragma mark - 加载的状态回调(WKNavigationDelegate)
96 -/// 页面开始加载时调用 96 +// 页面开始加载时调用
97 - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation { 97 - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
98 if (self.delegate && [self.delegate respondsToSelector:@selector(webViewDidStartLoad:)]) { 98 if (self.delegate && [self.delegate respondsToSelector:@selector(webViewDidStartLoad:)]) {
99 [self.delegate webViewDidStartLoad:self]; 99 [self.delegate webViewDidStartLoad:self];
100 } 100 }
101 } 101 }
102 -/// 当内容开始返回时调用 102 +// 当内容开始返回时调用
103 - (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation { 103 - (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation {
104 if (self.delegate && [self.delegate respondsToSelector:@selector(webView:didCommitWithURL:)]) { 104 if (self.delegate && [self.delegate respondsToSelector:@selector(webView:didCommitWithURL:)]) {
105 [self.delegate webView:self didCommitWithURL:self.wkWebView.URL]; 105 [self.delegate webView:self didCommitWithURL:self.wkWebView.URL];
106 } 106 }
107 -  
108 self.navigationItemTitle = self.wkWebView.title; 107 self.navigationItemTitle = self.wkWebView.title;
109 } 108 }
110 -/// 页面加载完成之后调用 109 +// 页面加载完成之后调用
111 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { 110 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
112 self.navigationItemTitle = self.wkWebView.title; 111 self.navigationItemTitle = self.wkWebView.title;
113 if (self.delegate && [self.delegate respondsToSelector:@selector(webView:didFinishLoadWithURL:)]) { 112 if (self.delegate && [self.delegate respondsToSelector:@selector(webView:didFinishLoadWithURL:)]) {
114 [self.delegate webView:self didFinishLoadWithURL:self.wkWebView.URL]; 113 [self.delegate webView:self didFinishLoadWithURL:self.wkWebView.URL];
115 } 114 }
116 -  
117 self.progressView.alpha = 0.0; 115 self.progressView.alpha = 0.0;
118 } 116 }
119 -/// 页面加载失败时调用 117 +// 页面加载失败时调用
120 - (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error { 118 - (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error {
121 if (self.delegate && [self.delegate respondsToSelector:@selector(webView:didFailLoadWithError:)]) { 119 if (self.delegate && [self.delegate respondsToSelector:@selector(webView:didFailLoadWithError:)]) {
122 [self.delegate webView:self didFailLoadWithError:error]; 120 [self.delegate webView:self didFailLoadWithError:error];
123 } 121 }
124 -  
125 self.progressView.alpha = 0.0; 122 self.progressView.alpha = 0.0;
126 } 123 }
127 -/// 加载 web 124 +// 加载 web
128 - (void)loadRequest:(NSURLRequest *)request { 125 - (void)loadRequest:(NSURLRequest *)request {
129 [self.wkWebView loadRequest:request]; 126 [self.wkWebView loadRequest:request];
130 } 127 }
131 -/// 加载 HTML 128 +// 加载 HTML
132 - (void)loadHTMLString:(NSString *)HTMLString { 129 - (void)loadHTMLString:(NSString *)HTMLString {
133 [self.wkWebView loadHTMLString:HTMLString baseURL:nil]; 130 [self.wkWebView loadHTMLString:HTMLString baseURL:nil];
134 } 131 }
135 -/// 刷新数据 132 +// 刷新数据
136 - (void)reloadData { 133 - (void)reloadData {
137 [self.wkWebView reload]; 134 [self.wkWebView reload];
138 } 135 }
139 -/// dealloc 136 +// dealloc
140 - (void)dealloc { 137 - (void)dealloc {
141 [self.wkWebView removeObserver:self forKeyPath:NSStringFromSelector(@selector(estimatedProgress))]; 138 [self.wkWebView removeObserver:self forKeyPath:NSStringFromSelector(@selector(estimatedProgress))];
142 } 139 }