CNLiveScanResultController.m 3.3 KB
//
//  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