I solved this problem with KVO.
First, addObserver for WKWebView scrollView contentSize like this:
addObserver(self, forKeyPath: "webView.scrollView.contentSize", options: .New, context: nil)
And then, get the change as follows:
override func observeValueForKeyPath(keyPath: String, ofObject object: AnyObject, change: [NSObject : AnyObject], context: UnsafeMutablePointer<Void>) { if keyPath == "webView.scrollView.contentSize" { if let nsSize = change[NSKeyValueChangeNewKey] as? NSValue { let height = nsSize.CGSizeValue().height // Do something here using content height. } } }
Easy to get height for web browsing content.
Remember to remove the observer:
removeObserver(self, forKeyPath: "webView.scrollView.contentSize", context: nil)
I am scrolling this line in deinit .
morizotter
source share