Uiwebview on uiscrollview tips

I have UIScrollview to allow pagination, and UIWebview for internal views. I know that you should not do this according to the reference to the classes of apples, but I do not see another option.

To make the answers and experience a little better, I turned off UIWebview scrolling using:

 [[[webView subviews] lastObject] setScrollEnabled:FALSE]; 

But now I'm looking for a solution to make the web view the right size, depending on the content. Is there an easy way to do this when the width of the webview remains the same, but the height grows (automatically) when you want to show the full article? This will fix the scroll problem as it sits in a scrollview that takes care of all the scrolls in this scenario.

It makes sense?

0
source share
2 answers

The documentation for UIWebView states:

Important: you must not embed UIWebView or UITableView objects in UIScrollView Objects. If you do this, unexpected behavior may occur because touch events for two objects may be mixed and erroneously processed.

A more suitable approach would be to add your UIWebView to the UIViewController with the UIScrollView (or UITableView) below it. I would understand how much space you have left, although to view the scroll, especially if you are dealing with an iPhone.

Hope pushing in the right direction.

Update:

Looking at this (I was sure there would be some way), it seems that the best approach I managed to find is to add a UIWebView to the UITableView header view.

  //create webview _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 280.0)]; //load request and scale content to fit [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.stackoverflow.com/"]]]; [_webView setScalesPageToFit:YES]; //add web view to table header view [[self tableView] setTableHeaderView:_webview]; 

This adds a UIWebView to the header of the table view before the cells are displayed at the bottom. Note that the presentation of the table header (and footer view) is also different from the section headings (and footer), so you can use these two if you use UITableViewStylePlain.

Be sure to extinguish the frame of the web view so that all visible cells are visible, otherwise the user will not be able to scroll the table view, since any touches will be intercepted by the web view.

This is still contrary to the UIWebView documentation (see above), but in practice this implementation actually works fine until the webview covers the entire area of ​​the scrollable view.

Here is a screenshot of the test application I made: enter image description here

Hope that helps :)

0
source

There is a better way to do this.

Starting with iOS 5.0, the apple exposes a UIScrollView inside the UIWebView. So, to resize the web view based on the content, here is what you do.

  • Make the parent UIWebView element a delegate of this UIWebView.
  • Implement webViewDidFinishLoad: and in this function just do it.

    CGSize sz = [webView.scrollView contentSize]; CGRect rect = webView.frame; rect.size.height = sz.height; webView.frame = rect;

Even if there is multiple downloads and the completion of the download, it does not matter, because in the end we will have to resize the web page to fit the content.

If you do not want the user to see dynamic resizing, you can simply set the alpha of the web view to 0, and when everything loads and you are done with the resizing, you can go to alpha-1 with animation.

0
source

All Articles