使用NJKWebViewProgress做webView的进度条
2016-11-30 本文已影响21人
Maggie的小蜗居
加上pod内容
pod 'NJKWebViewProgress', '~> 0.2.3'
导入头文件
#import "NJKWebViewProgressView.h"
#import "NJKWebViewProgress.h"
遵守协议
NJKWebViewProgressDelegate
实现
@property (nonatomic, strong) NJKWebViewProgressView *progressView;
@property (nonatomic, strong) NJKWebViewProgress *progressProxy;
- (void)viewDidLoad {
self.webView.delegate = self.progressProxy;
self.progressProxy.webViewProxyDelegate = self;
_progressView = [[NJKWebViewProgressView alloc] initWithFrame:barFrame];
_progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
[[self rac_signalForSelector:@selector(viewWillAppear:)] subscribeNext: ^(id x) {
@strongify(self)
[self.navigationController.navigationBar addSubview: self.progressView];
}];
[[self rac_signalForSelector:@selector(viewWillDisappear:)] subscribeNext: ^(id x) {
@strongify(self)
[self.progressView removeFromSuperview];
}];
}
//初始化协议
- (NJKWebViewProgress *)progressProxy
{
if ( !_progressProxy ) {
_progressProxy = [[NJKWebViewProgress alloc] init];
_progressProxy.webViewProxyDelegate = self;
_progressProxy.progressDelegate = self;
}
return _progressProxy;
}
#pragma mark - NJKWebViewProgressDelegate
- (void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
{
[self.progressView setProgress:progress animated:YES];
}