views:

2944

answers:

9

Sometimes, my UIWebView will have a grey box over part or all of the content. I can't make heads or tails of why it's happening. It happens regularly for certain content.

Thanks!

--Update--

It seems to occur when the webview is not immediately viewable on the screen -- ie i've got a scrollview, and the webview is below the fold.

--Update #2--

When I bring the content above the fold, it loads fine most of the time. There are still instances when the grey box is still showing up. The weird part is if i double-tap it, it finishes loading the content just fine. bizarre

--Update #3--

Okay, so it seems to be that if my uiwebview has a height greater than 1000px, a grey box appears on the rest of the content below 1000px. A double-tap reveals the actual content.

A: 

I have been dealing with this glitch as well, and have opened a bug report at apple. I would have commented above, but I don't have the 50 rep yet.

For anyone else encountering this glitch, send them a report, I included a full project demonstrating it, with a few screenshots from another app I am working on. The more bug reports they get on a topic, the more likely they are to address it, apparently.

https://bugreport.apple.com/

Ryan Townshend
+1  A: 

All UIViews have a size limit of 1024x1024 pixels. This is stated at the end of the Overview section of the UIView documentation.

If your web view must have more than 1024px of content, you will have to take it out of the parent scroll view and let it manage scrolling on its own.

benzado
Note: Prior to iOS 3.0, UIView instances may have a maximum height and width of 1024 x 1024. In iOS 3.0 and later, views are no longer restricted to this maximum size but are still limited by the amount of memory they consume. Therefore, it is in your best interests to keep view sizes as small as possible. Regardless of which version of iOS is running, you should consider using a CATiledLayer object if you need to create views larger than 1024 x 1024 in size.
jv42
Only of historical interest, but I think CATiledLayer wasn't available prior to 3.0.
benzado
A: 

I can't find any reference to the 1024px max content anywhere in the docs...

Antonio
UIView, Overview section: "Note: Prior to iOS 3.0, UIView instances may have a maximum height and width of 1024 x 1024. In iOS 3.0 and later, views are no longer restricted to this maximum size but are still limited by the amount of memory they consume. Therefore, it is in your best interests to keep view sizes as small as possible. Regardless of which version of iOS is running, you should consider using a CATiledLayer object if you need to create views larger than 1024 x 1024 in size."
jv42
A: 

Hi,

I've got the same problem. I put a UIWebView inside a big TableViewCell (>1024px) and when I scroll to the bottom of the cell, there is this grey box.

But, if I put a UILabel (also with a big size > 1024px), there is no grey box. So I think this has nothing to do with a max height of a UIView (BTW I can't find anything about this so called 1024 max height). I think it's more a UIWebView issue.

The solution for me is to reload the content of the webview when the grey box appears. Actually, I just have a HTMLString to load so I call [webview loadHTMLstring:] again, and the grey box disappear.

Hope that will help

A: 

Hi, I found a very intersting post about that, it solved the problem for me : link ttp://pinchzoom.com/blog/items/view/1386/one-of-the-problems-with-the-uikit-at-the-moment-is-an-issue-embedding-a-uiwebview-within-a-table

Hope that helps

Unfalkster
+1  A: 

Hi, I found a very intersting post about that, it solved the problem for me : link ttp://pinchzoom.com/blog/items/view/1386/one-of-the-problems-with-the-uikit-at-the-moment-is-an-issue-embedding-a-uiwebview-within-a-table

This solution is very efficient. But, is there anyone that find some manner to handle that problem without non-API functions?

Hami

Hamiseixas
A: 

hi, I've used stringByEvaluatingJavaScriptFromString plus moving UIWebView origin. Design overview: I had a set of controls(UIImage in this example) above(I mean frame.origin.y) UIWebView. So, layout was:

UIView
  UIScrollView
    UIImageView
    UIWebView

Since UIWebView doesn't support scrolling in such hierarchy I've rearrange it like:

UIView
  UIScrollView
    UIImageView
  UIWebView

My view controller is delegate for UIWebViewDelegate and UIScrollViewDelegate. Then,

- (void)viewDidLoad
{
  // set delegates
  self.scrollView.delegate = self;
  self.webView.delegate = self;

  // store original UIWebView position in ivar
  webViewPosY = self.webView.frame.origin.y;

  // load html into UIWebView
  [self.webView loadHTMLString:someHTML baseURL:nil];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
  // get UIWebView size and store in ivar
  webSize = [self.webView sizeThatFits:CGSizeMake(1.0,1.0)];

  // set proper content height for UIScrollView
  CGSize contentSize = self.scrollView.contentSize;
  contentSize.height = webViewPosY + webSize.height;
  self.scrollView.contentSize = contentSize; 

  // set UIWebView's frame height same as UIScrollView has
  CGRect wf = self.webView.frame;
  wf.size.height = self.scrollView.frame.size.height;
  self.webView.frame = wf;
}

// scrolling logic:
// 1.  if origin of UIWebView > 0 then move UIWebView itself
// 2.  if origin of UIWebView == 0 then scroll with javascript
// 3.  if origin is 0 and whole html is scrolled then move UIWebView again(this happens to support scroll "bouncing", or if you have some views below UIWebView
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
  CGFloat scrollPosY = self.scrollView.contentOffset.y;

  // (1) and (2) ifs
  // how much to move UIWebView
  CGFloat scrollOriginY = (scrollPosY >= webViewPosY) ? webViewPosY : scrollPosY;
  // how much to scroll via JS
  CGFloat scrollJSY = scrollPosY - scrollOriginY;

  // (3) if
  if ( scrollPosY > (webSize.height - scrollViewSize.height + webViewPosY ) )
    scrollOriginY += scrollPosY - (webSize.height - scrollViewSize.height + webViewPosY);

  // scroll with JS
  [self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.body.scrollTop = %f;", scrollJSY]];

  // move UIWebView itself
  CGRect wf = self.webView.frame;
  wf.origin.y = webViewPosY - scrollOriginY;
  self.webView.frame = wf;
}

This works just fine for me.

A: 

Nudging the UIScrollView in the UIWebView it fixes this for me:

[UIScrollView *webScroller= [[webView subviews] lastObject];    
[webScroller setContentOffset:CGPointMake(0,1) animated:NO];
[webScroller setContentOffset:CGPointMake(0,0) animated:NO];
Padraig
Note that this doesn't work in iOS 3.1 because it's a UIScroller that's in the UIWebView, not a UIScrollView.
Padraig