javascript - how to get proper UIWebView content height? - Stack Overflow

I am add UIWebView in View and That view in ScrollView.I want to get frame of the UIWebView Content. So

I am add UIWebView in View and That view in ScrollView.

I want to get frame of the UIWebView Content. So can I set the frame to view and scrollview?

I know we can get the height by using javascript. As mention below:

float height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] floatValue];

But when I am rotating the view and recalculate the height of the UIWebView content in didRotateFromInterfaceOrientation::(UIInterfaceOrientation)fromInterfaceOrientation method, then content height was increased.

So please suggest me how can I get the proper height when i am rotate the orientation?

Thanks.

I am add UIWebView in View and That view in ScrollView.

I want to get frame of the UIWebView Content. So can I set the frame to view and scrollview?

I know we can get the height by using javascript. As mention below:

float height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] floatValue];

But when I am rotating the view and recalculate the height of the UIWebView content in didRotateFromInterfaceOrientation::(UIInterfaceOrientation)fromInterfaceOrientation method, then content height was increased.

So please suggest me how can I get the proper height when i am rotate the orientation?

Thanks.

Share Improve this question edited Aug 23, 2012 at 7:57 Nayan 3,0062 gold badges18 silver badges33 bronze badges asked Aug 23, 2012 at 7:47 Smart DeveloperSmart Developer 722 silver badges10 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Adopt this method:

- (void) webViewDidFinishLoad:(UIWebView *)webView{
    CGRect frame = wvContent.frame;
    CGSize fittingSize = [wvContent sizeThatFits:CGSizeZero];
    frame.size = fittingSize;
    wvContent.frame = frame;
}

Then call this method everytime device rotating:

- (void) reloadContent
{
    CGRect frame = wvContent.frame;
    frame.size.height = 1;
    frame.size.width = wvContent.frame.size.width; // you should change webview's width here.
    wvContent.frame = frame;

    [wvContent loadHTMLString:yourHTML baseURL:nil]; // reload webview
}

Hope that help :)

Make sure that you are retrieving height when all the content is loaded.

You can add a method to calculate height in UIWebView's delegates method

- (void)webViewDidFinishLoad:(UIWebView *)webView{
    float height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] floatValue];
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745181266a4615428.html

相关推荐

  • javascript - how to get proper UIWebView content height? - Stack Overflow

    I am add UIWebView in View and That view in ScrollView.I want to get frame of the UIWebView Content. So

    16小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信