这是对早期问题的更新。一旦我用一些基于字符串的HTML内容加载UIWebView,有没有办法确定视图是否需要滚动才能看到整个内容?我正在寻找某种标志或方式来了解内容是否低于UIWebView的底部。
提前致谢!
答案 0 :(得分:1)
您可以继承UIWebView并使用以下initalizers:
-(id) initWithCoder:(NSCoder *)aDecoder
{
if(self = [super initWithCoder:aDecoder])
{
for (UIView* v in self.subviews){
if ([v isKindOfClass:[UIScrollView class]]){
self.scrollview = (UIScrollView*)v;
break;
}
}
}
return self;
}
- (id) initWithFrame:(CGRect)frame{
if(self = [super initWithFrame:frame])
{
for (UIView* v in self.subviews){
if ([v isKindOfClass:[UIScrollView class]]){
self.scrollview = (UIScrollView*)v;
break;
}
}
}
return self;
}
然后有一个名为
的属性@property (nonatomic, retain) UIScrollView *scrollview;
然后您可以访问UIWebView中的scrollview并查看其内容大小以查看它是否大于您的视图大小
答案 1 :(得分:0)
最简单的方法可能是使用Javascript来获取文档高度:
NSInteger height = [[myWebView stringByEvaluatingJavaScriptFromString:@“document.body.scrollHeight”] intValue];
(实际上没有测试过这个YMMV。不同的浏览器将文档高度放在不同的对象和属性中,我不记得哪个在Webkit中工作...请参阅How to get height of entire document with JavaScript?)
如果返回的高度大于UIWebView高度,则需要滚动。