Resize UIWebview page to match content

I know this has been asked many times, but I cannot get it to work. In short, my UIWebview pulls in some HTML that does not have a fixed height (the width is always the same), I just want the height to change accordingly.

I tried a number of fixes that I found on the Internet, but my problem is that the webview will resize to the correct size, but only for a short second, and then return to its original size.

I must point out that my point of view is caused by segue, this is the only thing I can think of, it’s different! I am wondering if the code works, but when segue finishes it with a crossfade, flipping, or having it redraw the webview.

Here is my current code (as I said, I tried many fixes, including Java versions, most of which do the same), I also played with scalesPageToFit and srollEnabled, as well as several ticks in the storyboard.

-(void)webViewDidFinishLoad:(UIWebView *)webView { NSLog(@"Starting Size : %f", headerWebView.frame.size.height); headerWebView.scalesPageToFit = YES; headerWebView.scrollView.scrollEnabled = NO; CGRect frame = headerWebView.frame; frame.size.width = frame.size.width; // I used this to test, I put 200 in and it changes then flicks back too frame.size.height = 1; headerWebView.frame = frame; frame.size.height = headerWebView.scrollView.contentSize.height; headerWebView.frame = frame; NSLog(@"Finished Size : %f", headerWebView.frame.size.height); } 

Magazines say:

Starting Size: 176,000000 Finish Size: 246.000000

Has anyone got an idea of ​​why Webview seems to be beautiful long enough for me to notice and then “shrink”?

+7
source share
1 answer

Has anyone got an idea of ​​why Webview just looks long enough for me to notice and then “shrink” backwards?

I would say that it seems beautiful, because you show the changes as they occur. Why not hide the web view at some earlier point in the life cycle of the view, or even in webViewDidFinishLoading? I am sharing my layout settings with IB if this can be of further help. Please advise if this helps or if additional information is needed. I use springs and struts, not an automatic machine. I would try this method to make sure that it works for you.

Hiding my data downloads on the Internet does not allow users to see anything until all my settings / data have been set.

  NSString *path = [[NSBundle mainBundle] bundlePath]; NSURL *baseURL = [NSURL fileURLWithPath:path]; [webView setAlpha:0]; [webView loadData:[dataString dataUsingEncoding:NSUTF8StringEncoding] MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:baseURL]; [UIView animateWithDuration:0.1 animations:^{ [webView setAlpha:1.0]; } completion:nil]; 

Web View Springs and StrutsWeb view settings

+3
source

All Articles