UIWebView with dynamic height inside a UIScrollView in Objective-C
<p>I am trying to make a UIWebView with "dynamic screen height". This webview is inside a UIScrollView, below other components. See the layout (it uses autolayout):</p>

<p><a href="https://i.stack.imgur.com/oFNIc.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oFNIc.jpg" alt="enter image description here"></a></p>

<p>My idea is to provide just one scroll (from UIScrollView - its working) and <strong>make the WebView viewport grow depending the content size</strong>. And its not working.</p>

<p>What I did to try to do this:</p>

<ol>
<li>UIWebView property "scale page to fit " is on;</li>
<li>UIWebView is unpaginated;</li>
<li>UIWebView does not allow user interaction.</li>
</ol>

<p>In my UIViewController:</p>

<pre><code>- (void) viewDidAppear:(BOOL)animated {
    NSString *urlString = @"MY URL GOES HERE";
    NSURL *url = [NSURL URLWithString:urlString];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
    [_webViewDescription loadRequest:urlRequest];
    _webViewDescription.delegate = self;
    _webViewDescription.scrollView.scrollEnabled = NO;
    _webViewDescription.scrollView.bounces = NO;
}
</code></pre>

<p>My UIWebViewDelegate:</p>

<pre><code>- (void)webViewDidFinishLoad:(UIWebView *)webView {
    CGRect frame = webView.frame;
    frame.size.height = 1;
    webView.frame = frame;
    CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
    frame.size = fittingSize;

    webView.frame = frame;


    NSLog(@"size: %f, %f", fittingSize.width, fittingSize.height);

    _myScrollView.contentSize = webView.bounds.size;
}
</code></pre>

<p>When I run the code, it prints the correct UIScrollView size and UIWebView size. The UIScrollView height got bigger, but the UIWebView maintains the same height from the first loading.</p>

<p>I am testing in a real device.</p>