直接代码 vv_wkView是懒加载
// MARK: - web
extension FF_CookingWebVC: WKNavigationDelegate{
funcwebView(_webView:WKWebView, didFinish navigation:WKNavigation!) {
webView.evaluateJavaScript("document.body.offsetHeight") { (obj, error)in
guardletheight = objas?CGFloatelse{return}
self.vv_wkView.scrollView.contentSize=CGSize(width:UIScreen.main.bounds.width, height: height)
}
webView.evaluateJavaScript("document.readyState", completionHandler: { (complete, error)in
ifcompleteas?String=="complete"&&!webView.isLoading{
webView.evaluateJavaScript("document.body.scrollHeight", completionHandler: { (height, error)in
letheight = webView.scrollView.contentSize.height
self.vv_wkView.scrollView.contentSize=CGSize(width:UIScreen.main.bounds.width, height: height)
})
}
self.ff_hudLoadingEnd(ff_animated:true)
})
}
}
如果url种有汉字 处理方法
url = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
self.vv_wkView.load(URLRequest(url:URL(string: url)!))