0

Webview のサイズを大きくしたいのですが、Html テキストに従って行が表示されますが、Web ビューのサイズが正しくありません。最初は固定フレームでコンテンツを表示しています。後でユーザーが行を選択すると、HTML テキストに従ってセルを拡張する必要があります。これを解決するのを手伝ってください、私が使用したコードは

enter code here  NSLog(@"web view and selected ==== %d ---%d",webView.tag,selectedRow);
//CGFloat webViewHeight = 0.0f;
if (webView.subviews.count > 0) {
    UIView *scrollerView = [webView.subviews objectAtIndex:0];
    if (scrollerView.subviews.count > 0) {
        UIView *webDocView = scrollerView.subviews.lastObject;
        if ([webDocView isKindOfClass:[NSClassFromString(@"UIWebDocumentView") class]])
            webViewHeight = webDocView.frame.size.height;

        NSLog(@"web view height is %d",webViewHeight);
    }

    }
4

1 に答える 1

0

実際の HTML ドキュメントの高さを取得するには、次のようにする必要があります。

NSUInteger height = [[webView stringByEvaluatingJavaScriptFromString:@"getDocHeight()"] intValue];

どこにgetDocHeightある:

function getDocHeight() {
  return Math.max(
    Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
    Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
    Math.max(document.body.clientHeight, document.documentElement.clientHeight)
  );
}

これが機能するには、HTML ドキュメントが完全にレンダリングされる (つまり、デリゲートが を受け取る) まで待つ必要がありますwebViewDidFinishLoad:

PS: 簡単なチェックを行いたい場合は、次の方法を試すこともできます。

    NSUInteger height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"] intValue];

これも機能するはずですが、上記のバージョンの方が移植性が高くなります。

于 2013-02-05T14:29:49.303 に答える