Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WKWebView not resizing when content changing

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?

like image 286
Luda Avatar asked Jun 07 '16 07:06

Luda


1 Answers

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 {

                }
            })
        }
    })
}
like image 158
NiTrOs Avatar answered Nov 07 '22 09:11

NiTrOs