WKWebView scroll issue

I'm working in a email client app, we are migrating from UIWebView to WKWebView and we are having issue with the scroll of WKWebView.


The app adds the email header (From, To, Subject controls) inside the webview.scrollview, it was working fine in UIWebView.


Now in WKWebView I add the controls in the same way and I change the scrollview content Size with:

- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {

[self.bodyWebView evaluateJavaScript:@"document.readyState" completionHandler:^(id result, NSError *error) {

if (error == nil && result != nil) {

[self.bodyWebView evaluateJavaScript:@"document.body.scrollHeight" completionHandler:^(id result2, NSError *error2) {

if (error2 == nil && result2 != nil)

{

CGFloat h = [result2 floatValue];

dispatch_async(dispatch_get_main_queue(), ^ {

self.bodyWebView.scrollView.contentSize =CGSizeMake(self.bodyWebView.scrollView.contentSize.width, h+ self.internalHeaderView.frameHeight);

});

}

}];

}

}];

[self shiftWebViewSubviews];

}


I debuged and the size is setting fine, I see all the email content, but the scroll stop some lines before the end, the same as the header height.


I tried overriding intrinsincContentSize in WKWebView, but doesn't work.

Replies

Which view is taller...scrollview or it's container?


Assumes iOS platform.

It is much easier to do these kinds of operations inside the HTML DOM.

Hello John, thanks for your answer, do you mean to add the headers inside the html?

Yes. I have seen a number of people have code that interacts with the legacy WebKit view hierarchy break when used with WKWebKit. I don't think WkWebView should be considered a true view. It isn't 100% stable either.