tags:

views:

2355

answers:

5

Hi:

we're trying to implement an article detail view for an RSS-like application. The windows has a UIScrollView that contains a UITextView (which is the title), a UIButton (which opens a gallery), and a UIWebView (with the body). The idea is that all these elements scroll together...

The problem is that whenever we have a body over 1000px tall, everything below that mark is truncated. We've heard that this is because that is the maximum height for a view, and since the Scroll is handled by the top UIScrollView, there is no way to see what's further down.

does anybody know a way around this?

Thanks!

---- update 1 ----

We've broken up the body into 900px-high chunks, but all webviews after the first one show no content...

UIScrollView *scroll=[[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
[scroll setBackgroundColor:[UIColor whiteColor]];
[scroll setCanCancelContentTouches:NO];
scroll.clipsToBounds = NO;  
scroll.indicatorStyle = UIScrollViewIndicatorStyleBlack;

//Título
CGRect tit =CGRectMake(5.0f, 0.0f, 315.f, 50.0f);
UILabel *titulo=[[UILabel alloc] initWithFrame:tit];
titulo.text=[itemNew objectForKey:@"titulo"];   
titulo.numberOfLines = 2;
titulo.font=[UIFont fontWithName:@"Helvetica" size:16.0f];
titulo.textColor=[self getColor:@"00336E"];
[scroll addSubview:titulo];
[titulo release];   

//Entradilla
float altura_entradilla=calcLabel([itemNew objectForKey:@"entradilla"], [UIFont boldSystemFontOfSize:16], 50, 315.0f);
CGRect ent_frame = CGRectMake(5.0f, 50.0f, 315.0f,altura_entradilla );
UILabel *entradilla=[[UILabel alloc] initWithFrame:ent_frame];
entradilla.text=[itemNew objectForKey:@"entradilla"];
entradilla.numberOfLines=4;
entradilla.font=[UIFont fontWithName:@"Helvetica" size:17.0f];
entradilla.textColor=[UIColor blackColor];
[scroll addSubview:entradilla];
[entradilla release];

NSString *cuerpo=[itemNew objectForKey:@"cuerpo"];

[scroll setContentSize:CGSizeMake(320.0f,40000.0f)];
[scroll setScrollEnabled:YES];  

webView = [[UIWebView alloc] initWithFrame:CGRectMake(5.0f, altura_entradilla+50, 315.0f, 900)];    
[webView loadHTMLString:cuerpo baseURL: [NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]];  
webView.detectsPhoneNumbers=NO;
webView.delegate=self;
[webView setScalesPageToFit:NO];
[scroll addSubview:webView];

webView.backgroundColor=[UIColor blackColor];
webView.userInteractionEnabled=NO;
[webView release];

if (altura_webview>900) {
   UIWebView *webView2 = [[UIWebView alloc] initWithFrame:CGRectMake(5.0f, altura_entradilla+50+900, 315.0f, 900)]; 
   [webView2 loadHTMLString:cuerpo baseURL: [NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]];  
   webView2.detectsPhoneNumbers=NO;
   webView2.delegate=self;
   [webView2 setScalesPageToFit:NO];
   [scroll addSubview:webView2];
   webView2.backgroundColor=[UIColor yellowColor];
   webView2.userInteractionEnabled=NO;
   [webView2 release];
}

self.view=scroll;
A: 
  1. Use more then one UIWebViews as body

  2. Are you using loadHTMLString to add content to webView? Try loadRequest method. There is no problem with 1024px when you are using loadRequest

oxigen
Hi: we're using loadHTMLString because the HTML is stored in a local variable (which was saved in a previous session). loadRequest can only be used when loading from a URL, right?The problem seems to be that when scrolling is handled by the parent UIScroll, and not by the UIWebView, it imposes a 1024px limit.
Antonio
Hm... In my current project i use UIScrollViews with contentSize.height more than 40000px. (many webViews, Labels and ImageViews) and there is no any problems with scroll. But if I try to create UIWebView highest then 1024px I have problemsloadRequest can be used to load data from local File
oxigen
We've tried breaking the body into several 900px-high webViews, but the second, third, etc. get blanked out (you can see the backgroundColor, but not the content)... I've edited the question to show the code.
Antonio
Antonio,Yes. It happens if you put webView or TextView into a ScrollView, but in unvisible part of scrollView. You must redraw them, when they came to visible region... To redraw you can (for example) change frame size of the visible now webView...
oxigen
ok, I think I'm beginning to see the light. Thanks oxigen. Another question: the only way to redraw the view is to change its frame size?
Antonio
Antonio, try [UIView setNeedsDisplay] Look this. There he has the same problem with offscreen views: http://cocoawithlove.com/2009/01/multiple-virtual-pages-in-uiscrollview.html
oxigen
Hi again: I found this and it really helped... http://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
Antonio
Thank's for this link
oxigen
A: 

check the contentSize on your UIScrollview.

I've not heard of a 1000 point limit (or seen it in bigger views I have in our app).

Roger Nolan
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.htmlUIView instances have a maximum height and width of 1024 x 1024. Views larger than this must be creating using CATiledLayers.
oxigen
That's not entirely true. Even though the documentation says that there is a max texture size of 1024, on both the original and 3G iPhones that max size is actually 2048 x 2048 for CALayers and UIViews.
Brad Larson
A: 

I had the same problem and I read and tried a few tips of this thread, but neither loading the content via loadHTMLString, nor using [_webView setNeedsDisplay] did changed anything for me. (I should try loading more UIWebViews, but I'm lazy:)

I used a quick and dirty fix using the scrollview delegate, which did the trick:

@interface ArticleViewController : UIViewController <UIScrollViewDelegate>

then fire up the view in init

_scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.view = _scrollView;
_scrollView.delegate = self;

and use the delgate's method to redraw the webView as it shows up

- (void) scrollViewDidEndDragging: (UIScrollView *) scrollView willDecelerate: (BOOL) willDecelerate
{
    CGRect frame = _webView.frame;
    frame.size = CGSizeMake(frame.size.width, frame.size.height + 1);
    _webView.frame = frame;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView 
{
    CGRect frame = _webView.frame;
    frame.size = CGSizeMake(frame.size.width, frame.size.height + 1);
    _webView.frame = frame;
}
Manuel Spuhler
A: 

Hi Antonio,

When you say :

We've tried breaking the body into several 900px-high webViews, but the second, third, etc. get blanked out (you can see the backgroundColor, but not the content)...

It seems to me that other persons have met this issue (I can't find the posts again), in fact UIWebviews seems to use only one HTML Interpreter. Meaning that if one UIWebView is loading HTML Content, others UIWebView won't load anything.

To solve that, you need to use UIWebView's delegate methods : didFinishLoad, and start loading the other webviews after that.

Please be aware that I'm not sure about what I'm saying, because I did not try it myself, but it might be a solution.

Unfalkster
A: 

The post marked as the answer has a link in it's last comment. That is the solution to this problem. I had this very same problem, and invoking [[webView _documentView] _webCoreNeedsDisplay]; in those 2 delegates solved it. Cheers.

Moszi
I tried the same solution but Apple rejected my app with a comment "3.3.1 Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs."The non-public API that is included in your application is _documentViewIs there any other solution to this problem?ThanksJugs
Jugs