WKWebView is not resizing when content changing.
Here is a code snippet:
@IBOutlet weak var containingView: UIView!
var webView: WKWebView!
override func viewDidLoad()
{
super.viewDidLoad()
let contentController = WKUserContentController();
self.webView = WKWebView(frame: CGRectMake(0, 0, self.view.frame.width, self.view.frame.height), configuration: WKWebViewConfiguration())
self.webView.autoresizingMask = [.FlexibleHeight]
self.webView.loadHTMLString(__, baseURL: __))
self.webView.scrollView.bounces = false
self.webView.scrollView.scrollEnabled = false
self.containingView.addSubview(self.webView)
}
What func should be added so I could intercept content size being changed and change the containingView size accordingly?
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
print("webview did enter did finish navigation")
webView.evaluateJavaScript("document.readyState", completionHandler: { (complete, error) in
if complete != nil {
webView.evaluateJavaScript("document.body.scrollHeight", completionHandler: { (result, error) in
if let heightOfContent = result as? CGFloat {
}
})
}
})
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With