title: Limit scrollable area within WKWebView content
body: <h1>Update:</h1>
  
  <p>I ran further experiments and as it turns out, I was mistaken about the solution working for <code>UIWebView</code>.  I had tested it, but didn't look close enough I guess.  After pondering matt's comments and re-reading the "solution" I found/mentioned, I noticed they weren't talking about webviews.  I've since hacked up a solution which embeds the my <code>UIWebView</code> inside of a <code>UIScrollView</code> of my own.  Then I "disable" the <code>UIWebView</code>'s scrollview by setting it's content size and frame to the size of the entire HTML document.  This approach should work for either <code>UIWebView</code> or <code>WKWebView</code>.  Once I clean up the solution, I'll come back and update.</p>
  
  <h1>Original:</h1>
  
  <p>I'm developing an iOS app that has a <code>WKWebView</code> for reading HTML content.  <strong>At times I need need to be able to restrict scrolling within a certain portion of the web content.</strong>  eg say the web content is 10,000 points vertically and I want to limit scrolling between 5,000 and 8,000.  I always show the full width.</p>
  
  <p><s>I found this solution <strong>for <code>UIWebView</code></strong>: <a href="https://stackoverflow.com/a/3973649">https://stackoverflow.com/a/3973649</a></p>
  
  <p>The solution suggests setting the <code>webview.scrollView.contentSize</code> like:</p>
  
  <pre><code>CGSize desiredContentSize = CGSizeMake(self.webView.scrollView.contentSize.width,
                                         8000-5000);
  self.webView.scrollView.contentSize = desiredContentSize;
  </code></pre>
  
  <p>and adjusting the <code>webview.scrollView.frame</code>'s origin to -5000;</p>
  
  <pre><code>CGRect scrollFrame;
  scrollFrame.origin = CGPointMake(0, -5000);
  scrollFrame.size = self.webView.frame.size;
  self.webView.scrollView.frame = scrollFrame;
  </code></pre>
  
  <p><strong>I have found this works well with <code>UIWebView</code>, but</s> it does not work with <code>WKWebView</code>.</strong>  With <code>WKWebView</code>, I am noticing that the scrollView's contentSize gets automatically reset to fit the content each time the user scrolls or when JavaScript updates the content.  This did not happen with <code>UIWebView</code>.</p>
  
  <p>I found I could "force" my desired contentSize to "stick" with this solution: <a href="https://stackoverflow.com/a/8214325/3352624">https://stackoverflow.com/a/8214325/3352624</a></p>
  
  <p>Unfortunately, this causes jitters when I hit the top and bottom of the viewable area.  Using this KVO approach is how I noticed <code>WKWebView</code> keeps resetting it's contentSize so frequently.</p>
  
  <p><strong>How can I restrict <code>WKWebView</code>'s scrollable area?  Is there a good way to prevent the contentSize from being changed?</strong></p>
  
  <p>For what it's worth, in this case, the HTML content is controlled content from an internal API.  The only javascript run is my own.  I am targeting iOS 8 and 9.</p>