V5.0.0bug修复

This commit is contained in:
wbzhan
2019-08-29 14:07:40 +08:00
parent 23c5d6f60d
commit 685a2b8676
17 changed files with 247 additions and 485 deletions
@@ -9,14 +9,16 @@
#import "PushMasssageWebViewController.h"
#import <WebKit/WebKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import "NJKWebViewProgressView.h"
#import "NJKWebViewProgress.h"
@interface PushMasssageWebViewController ()<NJKWebViewProgressDelegate,UIWebViewDelegate>
//#import "NJKWebViewProgressView.h"
//#import "NJKWebViewProgress.h"
@interface PushMasssageWebViewController ()<WKUIDelegate,WKNavigationDelegate>
{
NJKWebViewProgressView *_progressView;
NJKWebViewProgress *_progressProxy;
// NJKWebViewProgressView *_progressView;
// NJKWebViewProgress *_progressProxy;
}
@property(nonatomic,strong)UIWebView*myWebView;
//@property(nonatomic,strong)UIWebView*myWebView;
Strong WKWebView *webView;
Strong UIProgressView *wkProgressView;
@property(nonatomic,strong)UIActivityIndicatorView*indicator;
@end
@@ -28,7 +30,7 @@
// Do any additional setup after loading the view.
[self addTitleViewWithTitle:self.pushtitle];
[self creatwebView];
[self creatWkwebView];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault];
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
@@ -58,32 +60,60 @@
}
-(void)initWebView
{
self.myWebView=[[UIWebView alloc]initWithFrame:self.view.bounds];
NSString*filepath=[[NSBundle mainBundle]pathForResource:@"shuomingshu" ofType:@"html"];
NSString*html=[NSString stringWithContentsOfFile:filepath encoding:NSUTF8StringEncoding error:nil];
[self.myWebView loadHTMLString:html baseURL:[NSURL URLWithString:filepath]];
[self.view addSubview:self.myWebView];
}
//-(void)initWebView
//{
// self.myWebView=[[UIWebView alloc]initWithFrame:self.view.bounds];
// NSString*filepath=[[NSBundle mainBundle]pathForResource:@"shuomingshu" ofType:@"html"];
// NSString*html=[NSString stringWithContentsOfFile:filepath encoding:NSUTF8StringEncoding error:nil];
//
// [self.myWebView loadHTMLString:html baseURL:[NSURL URLWithString:filepath]];
//
// [self.view addSubview:self.myWebView];
//
//}
#pragma mark - WKWeb IOS 8之后用
-(void)creatWkwebView
{
WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
//NSString*url=[NSString stringWithFormat:@"http://www.baidu.com"];
//NSURLRequest*requst=[NSURLRequest requestWithURL:[NSURL URLWithString:url]];
NSURLRequest*requst=[NSURLRequest requestWithURL:[NSURL URLWithString:self.pushlink]];
[webView loadRequest:requst];
[self.view addSubview:webView];
//webView.navigationDelegate = self;
self.webView = [[WKWebView alloc]init];
self.webView.UIDelegate = self;
self.webView.navigationDelegate = self;
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.pushlink]]];
[self.view addSubview:self.webView];
self.wkProgressView = [[UIProgressView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 2)];
self.wkProgressView.progressTintColor = [UIColor greenColor];
[self.view addSubview:self.wkProgressView];
// 给webview添加监听
[self.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];
[self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
if ([keyPath isEqual:@"estimatedProgress"] && object == self.webView) {
[self.wkProgressView setAlpha:1.0f];
[self.wkProgressView setProgress:self.webView.estimatedProgress animated:YES];
if (self.webView.estimatedProgress >= 1.0f) {
[UIView animateWithDuration:0.3 delay:0.3 options:UIViewAnimationOptionCurveEaseOut animations:^{
[self.wkProgressView setAlpha:0.0f];
} completion:^(BOOL finished) {
[self.wkProgressView setProgress:0.0f animated:YES];
}];
}
}else{
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
- (void)dealloc{
[self.webView removeObserver:self forKeyPath:@"estimatedProgress"];
[self.webView setNavigationDelegate:nil];
[self.webView setUIDelegate:nil];
}
// 页面开始加载时调用
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation
{
@@ -109,84 +139,84 @@
[super viewDidDisappear:animated];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController.navigationBar addSubview:_progressView];
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[_progressView removeFromSuperview];
}
//-(void)viewWillAppear:(BOOL)animated{
//
// [super viewWillAppear:animated];
// [self.navigationController.navigationBar addSubview:_progressView];
//}
//
//-(void)viewWillDisappear:(BOOL)animated{
// [super viewWillDisappear:animated];
// [_progressView removeFromSuperview];
//
//}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)creatwebView{
self.myWebView.opaque=NO;
self.myWebView.backgroundColor=[UIColor clearColor];
self.myWebView=[[UIWebView alloc]initWithFrame:self.view.bounds];
[self.view addSubview:self.myWebView];
//self.myWebView.delegate=self;
_progressProxy = [[NJKWebViewProgress alloc] init]; // instance variable
self.myWebView.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;
NSURLRequest*requst=[NSURLRequest requestWithURL:[NSURL URLWithString:self.pushlink]];
//NSString*url=[NSString stringWithFormat:@"https://bg.zhangxinyanv5.top/ueditorHtml/1484032071200.html"];
//NSURLRequest*requst=[NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[self.myWebView loadRequest:requst];
}
-(void)webViewDidStartLoad:(UIWebView *)webView{
[_indicator startAnimating];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
[_indicator stopAnimating];
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
[_indicator stopAnimating];
}
-(void)initIndicatorView{
_indicator=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
_indicator.frame=CGRectMake(0.f,0.f,100.f, 100.f);
_indicator.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
_indicator.center=self.view.center;
_indicator.layer.masksToBounds=YES;
_indicator.layer.cornerRadius=5;
[self.view addSubview:_indicator];
}
#pragma mark - NJKWebViewProgressDelegate
-(void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
{
[_progressView setProgress:progress animated:YES];
//self.title = [self.myWebView stringByEvaluatingJavaScriptFromString:@"document.title"];
}
//-(void)creatwebView{
//
// self.myWebView.opaque=NO;
// self.myWebView.backgroundColor=[UIColor clearColor];
// self.myWebView=[[UIWebView alloc]initWithFrame:self.view.bounds];
// [self.view addSubview:self.myWebView];
//
// //self.myWebView.delegate=self;
//
// _progressProxy = [[NJKWebViewProgress alloc] init]; // instance variable
// self.myWebView.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;
//
// NSURLRequest*requst=[NSURLRequest requestWithURL:[NSURL URLWithString:self.pushlink]];
//
// //NSString*url=[NSString stringWithFormat:@"https://bg.zhangxinyanv5.top/ueditorHtml/1484032071200.html"];
// //NSURLRequest*requst=[NSURLRequest requestWithURL:[NSURL URLWithString:url]];
// [self.myWebView loadRequest:requst];
//
//
//}
//
//-(void)webViewDidStartLoad:(UIWebView *)webView{
//
// [_indicator startAnimating];
//
//}
//-(void)webViewDidFinishLoad:(UIWebView *)webView{
//
// [_indicator stopAnimating];
//
//}
//-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
//
// [_indicator stopAnimating];
//}
//
//-(void)initIndicatorView{
//
// _indicator=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
// _indicator.frame=CGRectMake(0.f,0.f,100.f, 100.f);
// _indicator.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
// _indicator.center=self.view.center;
// _indicator.layer.masksToBounds=YES;
// _indicator.layer.cornerRadius=5;
// [self.view addSubview:_indicator];
//
//}
//
//#pragma mark - NJKWebViewProgressDelegate
//-(void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
//{
// [_progressView setProgress:progress animated:YES];
// //self.title = [self.myWebView stringByEvaluatingJavaScriptFromString:@"document.title"];
//}