Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何获得适当的UIWebView内容高度?_Javascript_Iphone_Ios_Uiwebview - Fatal编程技术网

Javascript 如何获得适当的UIWebView内容高度?

Javascript 如何获得适当的UIWebView内容高度?,javascript,iphone,ios,uiwebview,Javascript,Iphone,Ios,Uiwebview,我在视图中添加UIWebView,并在ScrollView中添加该视图 我想获取UIWebView内容的框架。那么我可以将框架设置为view和scrollview吗 我知道我们可以通过使用javascript获得高度。如下所述: float height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] floatValue]; 但当我在didRotateFromInterfac

我在视图中添加UIWebView,并在ScrollView中添加该视图

我想获取UIWebView内容的框架。那么我可以将框架设置为view和scrollview吗

我知道我们可以通过使用javascript获得高度。如下所述:

float height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] floatValue];
但当我在didRotateFromInterfaceOrientation::UIInterfaceOrientationfromInterfaceOrientation方法中旋转视图并重新计算UIWebView内容的高度时,内容高度增加了

因此,请建议我如何在旋转方向时获得适当的高度

谢谢。

采用以下方法:

- (void) webViewDidFinishLoad:(UIWebView *)webView{
    CGRect frame = wvContent.frame;
    CGSize fittingSize = [wvContent sizeThatFits:CGSizeZero];
    frame.size = fittingSize;
    wvContent.frame = frame;
}
然后每次设备旋转时调用此方法:

- (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
}
希望帮助:

采用此方法:

- (void) webViewDidFinishLoad:(UIWebView *)webView{
    CGRect frame = wvContent.frame;
    CGSize fittingSize = [wvContent sizeThatFits:CGSizeZero];
    frame.size = fittingSize;
    wvContent.frame = frame;
}
然后每次设备旋转时调用此方法:

- (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
}

希望提供帮助:

确保在加载所有内容时检索高度

可以在UIWebView的委托方法中添加计算高度的方法

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

确保在加载所有内容时检索高度

可以在UIWebView的委托方法中添加计算高度的方法

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

下面是我要查看的代码:在这个web视图中,设备旋转后底部有额外的空白。将此代码添加到viewdidload wvContent.autoresizingMask=UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;好的,让我先看看你的代码。我将很快发送给您:0这是我要查看的代码:在此web视图中,设备旋转后底部有额外的空白。将此代码添加到viewdidload wvContent.autoresizingMask=UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;好的,让我先看看你的代码。我将很快发送给您:0