Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.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
Ios 如何获取uiwebview的内容宽度?_Ios_Uiwebview_Gif - Fatal编程技术网

Ios 如何获取uiwebview的内容宽度?

Ios 如何获取uiwebview的内容宽度?,ios,uiwebview,gif,Ios,Uiwebview,Gif,我像这样加载Gif图像 [webView2 loadData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Apple_jumps" ofType:@"gif"]] MIMEType:@"image/gif" textEncodingName:nil baseURL:nil]; 我想设置uiwebview的中心位置,但我无法获得内容的宽度。请提供帮助。您可以使用javascript中的docume

我像这样加载Gif图像

[webView2 loadData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Apple_jumps" ofType:@"gif"]] MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];

我想设置uiwebview的中心位置,但我无法获得内容的宽度。请提供帮助。

您可以使用javascript中的
document.height
document.width

// in init
_WebView.delegate = YourClass; // probably self

- (void) webViewDidFinishLoad:(UIWebView *)webview
{
  int w = [[_WebView stringByEvaluatingJavaScriptFromString:@"document.width"] floatValue];
  _WebView.userInteractionEnabled = w > 200;
}

此处的更多信息:

document.width始终返回iphone屏幕的宽度(320),document.height可以正常工作。否,document.width返回页面的宽度。如果您的页面使用iphone的meta标记,则大小为320px。