- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{//如果将cangoback写在此方法里面只能执行一次,如果当前网页跳转不是新的web就不能执行
}
//通过KVO的方式获取进度条,title,是否可以返回
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
if ([keyPath isEqualToString:@"title"]) {
self.navigationItem.title = self.isShowTitle ? self.webView.title : @"";
}else if ([keyPath isEqualToString:@"estimatedProgress"]){
if (object == self.webView) {
[_progressView setProgress:self.webView.estimatedProgress animated:true];
if (self.webView.estimatedProgress >= 1.0) {
[_progressView setProgress:0 animated:false];
}
}
}else if ([keyPath isEqualToString:@"canGoBack"]){
if (self.webView.canGoBack) {
UIBarButtonItem * leftBtn1 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"zhige_chat_back"] style:UIBarButtonItemStylePlain target:self action:@selector(goBack)];
UIBarButtonItem * leftBtn2 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"colseWeb"] style:UIBarButtonItemStylePlain target:self action:@selector(popView)];
leftBtn2.imageInsets = UIEdgeInsetsMake(0, -30, 0, 0);
self.navigationItem.leftBarButtonItems = @[leftBtn1,leftBtn2];
}else{
UIBarButtonItem * leftBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"zhige_chat_back"] style:UIBarButtonItemStylePlain target:self action:@selector(popView)];
self.navigationItem.leftBarButtonItems = @[leftBtn];
}
}
}