Thank you for looking at my question. Currently, I have several input fields and a WKWebView embedded in a UIScrollView. Before any events fire, all the subviews fit inside the scroll view with no issue. I'm dynamically setting the WK's height based on document.body.scrollHeight which is captured in the DidFinishNavigation delegate located in WKNavigationDelegate. After the WK's height is set, the WK extends past the view-able content. Here's the code which I'm trying to force the scrollview to resize itself.
public async void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
//get the webView's initial height var initialHeight = webView.Frame.Height; //get height of HTML's document.body.scrollHeight var contentHeight = await GetContentHeight(); //create new frame for webview CGRect newWebViewFrame = new CGRect(webView.Frame.X, webView.Frame.Y, webView.Frame.Width, contentHeight); //set webview's frame webView.Frame = newWebViewFrame; //get the difference of webView's initial height and webView's current height var differenceInHeight = contentHeight - initialHeight; //create new cgrect and set the height to svMain's height + the difference in height of the HTML document CGRect newScrollViewFrame = new CGRect(0, 0, svMainScroller.Frame.Width, svMainScroller.Frame.Height + differenceInHeight); //set MainScroller's frame svMainScroller.Frame = newScrollViewFrame; //force scrolling svMainScroller.ScrollEnabled = true; //scrolling should be handled in the main scroller webView.ScrollView.ScrollEnabled = false; svMainScroller.SizeToFit(); }
The desired effect is to have the scroll view be able to scroll to the end of the newly defined height. Any tips on how would I go about doing that would be greatly appreciated.