Reputation: 2060
I am using webview inside the uicollectionview cell. I update the webview height constraint constant after the html was loaded. in following way.
public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
print("Load Completed")
webView.evaluateJavaScript("document.readyState", completionHandler: { (complete, error) in
if complete != nil {
self.webview.evaluateJavaScript("document.body.offsetHeight", completionHandler: { (height, error) in
DispatchQueue.main.async {
self.webviewHeightConstraint.constant = height as! CGFloat
print("Height ",height as! CGFloat)
self.webview.setNeedsUpdateConstraints()
}
})
}
})
}
it give correct height value but ui is not changed until i scrolled little. But i start the scroll, webview height changed correctly. What is the issue here. Please help me.
Thank you,
Upvotes: 0
Views: 1096
Reputation: 87
Migrating to WKWebView
The full code for WKWebView would then be:
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
webView.frame.size.height = 1
webView.frame.size = webView.scrollView.contentSize
}
Upvotes: 0
Reputation: 100533
Replace
self.webview.setNeedsUpdateConstraints()
with
self.view.layoutIfNeeded()
Upvotes: 1