CNLiveScanResultController.m
3.3 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
//
// CNLiveScanResultController.m
// CNLiveQrCodeModule
//
// Created by 153993236@qq.com on 11/12/2019.
// Copyright (c) 2019 153993236@qq.com. All rights reserved.
//
#import "CNLiveScanResultController.h"
#import "QMUIKit.h"
#import "CNLiveCategory.h"
#import "CNLiveQrCodeNavigationBar.h"
#import "CNLiveWebView.h"
@interface CNLiveScanResultController () <CNLiveQrCodeNavigationBarDelegate, CNLiveWebViewDelegate>
@property (nonatomic, strong) CNLiveQrCodeNavigationBar *navigationBar;
@property (nonatomic, strong) CNLiveWebView *webView;
@end
@implementation CNLiveScanResultController
#pragma mark - 生命周期
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
[self setupSubView];
if ([self.jump_URL hasPrefix:@"http://"]||[self.jump_URL hasPrefix:@"https://"]) {
[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.jump_URL]]];
} else {
[_webView loadHTMLString:[self html:self.jump_URL]];
}
}
- (NSString *)html:(NSString *)url{
return [NSString stringWithFormat:@"<div style=\"font-size:40px\">%@</div>",url];
}
- (void)setupSubView {
[self.view addSubview:self.navigationBar];
[self.view addSubview:self.webView];
}
#pragma mark - 代理
- (void)navigationBar:(CNLiveQrCodeNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{
if ([actionEvents isEqualToString:@"1"]) {
[self goBack];
}
}
- (void)webView:(CNLiveWebView *)webView didFinishLoadWithURL:(NSURL *)url {
NSLog(@"didFinishLoad");
if(webView.navigationItemTitle.length != 0){
self.navigationBar.title.text = webView.navigationItemTitle;
}else{
self.navigationBar.title.text = @"识别结果";
}
}
- (void)webView:(CNLiveWebView *)webView didFailLoadWithError:(NSError *)error{
}
#pragma mark - 懒加载
- (CNLiveQrCodeNavigationBar *)navigationBar {
if (!_navigationBar) {
_navigationBar = [[CNLiveQrCodeNavigationBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)];
_navigationBar.delegate = self;
_navigationBar.title.textColor = [UIColor blackColor];
_navigationBar.delegate = self;
UIImage *image = [self getImageWithImageName:@"code_back_black_b" bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveScanResultController class]];
[_navigationBar.left setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
_navigationBar.right = nil;
}
return _navigationBar;
}
- (CNLiveWebView *)webView {
if (!_webView) {
_webView = [CNLiveWebView webViewWithFrame:CGRectMake(0, NavigationContentTop, SCREEN_WIDTH, SCREEN_HEIGHT-NavigationContentTop)];
_webView.isNavigationBarOrTranslucent = NO;
_webView.delegate = self;
}
return _webView;
}
#pragma mark - 响应方法
- (void)goBack {
if (self.presentingViewController != nil) {
[self dismissViewControllerAnimated:YES completion:nil];
}
else {
[self.navigationController popViewControllerAnimated:YES];
}
}
@end