| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- //
- // TGWebViewController.m
- // TGWebViewController
- //
- // Created by 赵群涛 on 2017/9/15.
- // Copyright © 2017年 QR. All rights reserved.
- //
- #import "TGWebViewController.h"
- #import "TGWebProgressLayer.h"
- #import <WebKit/WebKit.h>
- @interface TGWebViewController ()<WKNavigationDelegate>
- @property (nonatomic, strong)WKWebView *tgWebView;
- @property (nonatomic, strong)TGWebProgressLayer *webProgressLayer;
- @end
- @implementation TGWebViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.view.backgroundColor = [UIColor whiteColor];
- self.automaticallyAdjustsScrollViewInsets = NO;
- self.navigationItem.title = self.webTitle;
- [self setUpUI];
- }
- - (void)setUpUI {
-
-
- UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- backBtn.frame = CGRectMake(0, 0, 14, 28);
- [backBtn setImage:[UIImage imageNamed:@"arrow_left"] forState:UIControlStateNormal];
- [backBtn addTarget:self action:@selector(backButton:) forControlEvents:UIControlEventTouchUpInside];
- self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
-
- self.tgWebView = [[WKWebView alloc] initWithFrame:self.view.bounds];
- self.tgWebView.navigationDelegate =self;
- NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.url]];
- [self.tgWebView loadRequest:request];
- [self.view addSubview:self.tgWebView];
-
-
- self.webProgressLayer = [[TGWebProgressLayer alloc] init];
- self.webProgressLayer.frame = CGRectMake(0, 42, WIDTH, 2);
- self.webProgressLayer.strokeColor = self.progressColor.CGColor;
- [self.navigationController.navigationBar.layer addSublayer:self.webProgressLayer];
-
-
- }
- - (void)backButton:(UIButton *)btn {
- [self.navigationController popViewControllerAnimated:YES];
- [self.webProgressLayer removeFromSuperlayer];
- }
- #pragma mark - UIWebViewDelegate
- - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
- [self.webProgressLayer tg_startLoad];
- }
- - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
- [self.webProgressLayer tg_finishedLoadWithError:nil];
- }
- - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error {
- [self.webProgressLayer tg_finishedLoadWithError:error];
-
- }
- - (void)dealloc {
- [self.webProgressLayer tg_closeTimer];
- [_webProgressLayer removeFromSuperlayer];
- _webProgressLayer = nil;
- }
- @end
|