【发布时间】:2011-02-28 02:54:23
【问题描述】:
我正在使用UIWebView 以 HTML 字符串的形式显示内容 - 不是网站,高于 iPhone 的屏幕,无需在 webView 本身中滚动,将其留给父 scrollView .
为了实现这一点,我需要一种方法来获取总文档大小(包括可滚动区域)来设置 webView 的高度。我尝试了许多不同的 Javascript 解决方案:
(document.height !== undefined) ? document.height : document.body.offsetHeight // Returns height of UIWebView
document.body.offsetHeight // Returns zero
document.body.clientHeight // Returns zero
document.documentElement.clientHeight // Returns height of UIWebView
window.innerHeight // Returns height of UIWebView -2
document.body.scrollHeight // Returns zero
有没有真正有效的解决方案?
当前(非工作)代码:
[[[self.singlePost.contentText subviews] lastObject] setScrollEnabled:NO];
int content_height = [[self.singlePost.contentText stringByEvaluatingJavaScriptFromString: @"document.body.offsetHeight"] intValue];
NSLog(@"Content_height: %d", content_height);
CGRect rect = self.singlePost.contentText.frame;
rect.size.height = content_height;
self.singlePost.contentText.frame = rect;
【问题讨论】:
-
document.body.scrollHeight工作吗?
标签: javascript iphone objective-c uiwebview uiscrollview