使用 JS 代码获取内容高度
web 加载完成之后。注:由于图片的原因可能还是不一定准。
- (void)webViewDidFinishLoad:(UIWebView *)webView {
CGFloat height = [[self.webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"] floatValue];
}
KVO
[self.webView.scrollView addObserver:self
forKeyPath:@"contentSize"
options:NSKeyValueObservingOptionNew
context:nil];
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
CGSize size = [[change objectForKey:NSKeyValueChangeNewKey] CGSizeValue];
}
RAC
[[self.webView.scrollView rac_valuesAndChangesForKeyPath:@"contentSize"
options:NSKeyValueObservingOptionNew
observer:nil]
subscribeNext:^(RACTuple *x) {
@strongify_self
CGSize size = [[[[x allObjects] lastObject] objectForKey:NSKeyValueChangeNewKey] CGSizeValue];
}];
1
网友评论