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