views:

869

answers:

2

Does anyone know if this solution can be approved by Apple submission app?

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    CGFloat webViewHeight = 0.0f;
    if (self.subviews.count > 0) {
        UIView *scrollerView = [self.subviews objectAtIndex:0];
        if (scrollerView.subviews.count > 0) {
            UIView *webDocView = scrollerView.subviews.lastObject;
            if ([webDocView isKindOfClass:[NSClassFromString(@"UIWebDocumentView") class]])
                webViewHeight = webDocView.frame.size.height;
        }
    }
}

Thanks. Hami.

A: 

Rather than messing around with private classes that may change and break your app, why not use -stringByEvaluatingJavaScriptFromString: to resize the web page with javascript?

Rob Napier
Yes. It should work. But i'm having a huge problem when orientation changed.When i use the notification method, that notification occurs before application layout changed. So, stringByEvaluatingJavaScriptFromString returns wrong values.I tried to add a delay before calling stringByEvaluatingJavaScriptFromString and it works. But delay is not very accurate method :)Thanks anyway
Hamiseixas
I don't think I understand what you mean here about -stringByEvaluatingJavaScriptFromString returning wrong values. I mean to use it to actually change the size of the javascript window in response to the orientation change, not ask the view what its size is. It shouldn't be returning anything.
Rob Napier
The OP want to determine the height of the UIWebView, not change it. I guess he wants to embed a UIWebView in a UITableViewCell.
Aurélien Vallée
A: 

Implement the UIWebViewDidfinishLoad delegate method and use the following code

Hi ,

You can use the following methods to solve your problem.

For getting the pageOffset:

int pageYOffset = [[webViewObj stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];

For getting the total scroll height of a webpage:

int scrollHeight = [[webViewObj stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight"] intValue];

For scrolling the webpage to a particular offset:

[webViewObj stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.body.scrollTop = %d",scrollHeight ]];

Biranchi