UIWebView をセットアップする以下のコードがあります。
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById(\"image\").src=\"q%@.png\";", self.imageIndex]];
NSLog(@"%f", [[webView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"image\").height;"] floatValue]);
CGFloat width = [[webView stringByEvaluatingJavaScriptFromString:@"document.width"] floatValue];
CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.height"] floatValue];
CGSize contentSize = CGSizeMake(width, height);
[self setUpNewSize:contentSize];
}
ID を持つオブジェクトの新しいイメージを設定しました (そして動作します)。でも大きさは変わらない。ご覧のとおり、NSLog を使用して高さの値を出力しますが、高さは 0.0000 と表示されます。
これは私のHTMLファイルです:
<!DOCTYPE html>
<html>
<head>
<title>Question 1</title>
</head>
<body>
<h3 id="header">Question 1</h3>
<img id="image" src="" alt="" width="100%">
</body>
</html>
画像ごとに高さが異なり、動的に変化します。私の質問は、stringByEvaluatingJavaScriptFromString を呼び出したときにドキュメントと img の高さが変わらない理由です。おそらく、いくつかのリロード メソッドを作成する必要がありますか?