WebViewVC.m
3.31 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
111
112
113
114
115
116
117
118
//
// WebViewVC.m
// ChinaFM
//
// Created by zxx on 16/9/14.
// Copyright © 2016年 XRG. All rights reserved.
//
#import "WebViewVC.h"
#import "NJKWebViewProgressView.h"
@interface WebViewVC () {
NJKWebViewProgressView *_progressView;
NJKWebViewProgress *_progressProxy;
}
@property (strong, nonatomic) UIWebView *webView;
@end
@implementation WebViewVC
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
self.webView.frame = self.view.bounds;
}
- (void)viewDidLoad {
[super viewDidLoad];
_webView = [[UIWebView alloc] initWithFrame:CGRectZero];
[self.view addSubview:_webView];
_progressProxy = [[NJKWebViewProgress alloc] init];
_webView.delegate = _progressProxy;
_progressProxy.webViewProxyDelegate = self;
_progressProxy.progressDelegate = self;
CGFloat progressBarHeight = 2.f;
CGRect navigationBarBounds = self.navigationController.navigationBar.bounds;
CGRect barFrame = CGRectMake(0, navigationBarBounds.size.height - progressBarHeight, navigationBarBounds.size.width, progressBarHeight);
_progressView = [[NJKWebViewProgressView alloc] initWithFrame:barFrame];
_progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
[self loadURL];
}
- (void)setCustomNavigationBar{
UINavigationBar *navBar = self.navigationController.navigationBar;
navBar.translucent = NO;
// navBar.tintColor = uicolo
UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"返回键-1"] style:UIBarButtonItemStylePlain target:self action:@selector(leftBarItemFunc:)];
self.navigationItem.leftBarButtonItem = leftBarItem;
}
- (void)leftBarItemFunc:(id)sender
{
if (self.navigationController.viewControllers.count > 1) {
[self.navigationController popViewControllerAnimated:YES];
}
else{
[self dismissViewControllerAnimated:YES completion:^{
}];
}
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = NO;
[self.navigationController.navigationBar addSubview:_progressView];
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// Remove progress view
// because UINavigationBar is shared with other ViewControllers
[_progressView removeFromSuperview];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)loadURL {
if (self.webUrl) {
NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:self.webUrl]];
[_webView loadRequest:req];
}
}
#pragma mark - NJKWebViewProgressDelegate
-(void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
{
[_progressView setProgress:progress animated:YES];
self.title = [_webView stringByEvaluatingJavaScriptFromString:@"document.title"];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end