I cannot get the UIScrollView to adjust its size based on UIWebView

There are so many discussions on the subject between WebView in ScrollView or ScrollView in WebView that I'm completely lost!

In my case, I have a ScrollView which owns a UIImageView of a fixed size and a UIWebView of a variable size.

I used the following solution which seems to correctly compute the height, according to NSLog() output:

* Edit * My web view is initialised as follow:

    CABBndGMedia *htmlMedia = [[currentPOI listMediaHtml] objectAtIndex:0];
    NSData *htmlData = [NSData dataWithContentsOfURL:[htmlMedia localMediaFilename]];
    poiHtml.delegate = self;
    [poiHtml loadData:htmlData MIMEType:@"text/html" textEncodingName:@"" baseURL:[NSURL URLWithString:@""]];
    poiHtml.scalesPageToFit = YES;

And then:

-(void)webViewDidFinishLoad:(UIWebView *)webView{

    CGRect frame = poiHtml.frame;
    frame.size.height = 1;
    poiHtml.frame = frame;
    CGSize fittingSize = [poiHtml sizeThatFits:CGSizeZero];
    frame.size = fittingSize;
    poiHtml.frame = frame;

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

}

* Edit * After changing the Scrollview background colour, I realised that the WebView doesn't change its height, despite the fittingSize.height value display.

This problem seems to be very "weather" depend according to everything I read in Stackoverflow where some solutions seem to work for someone, not for the other.... Anyway, what could I miss to get this solution, which seem to be the best one, working?

Regards,


The UIScrollView s frame should be the boundaries within which you wish the content to be clipped. So probably the size of your screen.

You need to set the contentSize property of the scroll view to be the full size that you have calculated. Then the scroll view will allow you to scroll within that size.

链接地址: http://www.djcxy.com/p/77424.html

上一篇: 以编程方式调整/调整动态html以适应UIWebView

下一篇: 我无法让UIScrollView根据UIWebView调整其大小