iPhone UIWebView高度

Ham*_*xas 0 iphone uiwebview

有谁知道这个解决方案是否可以被Apple提交的应用程序批准?

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    CGFloat webViewHeight = 0.0f;
    if (self.subviews.count > 0) {
        UIView *scrollerView = [self.subviews objectAtIndex:0];
        if (scrollerView.subviews.count > 0) {
            UIView *webDocView = scrollerView.subviews.lastObject;
            if ([webDocView isKindOfClass:[NSClassFromString(@"UIWebDocumentView") class]])
                webViewHeight = webDocView.frame.size.height;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢.哈密​​.

Bir*_*chi 7

实现UIWebViewDidfinishLoad委托方法并使用以下代码

嗨,

您可以使用以下方法来解决您的问题.

获取pageOffset:

int pageYOffset = [[webViewObj stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];

要获取网页的总滚动高度:

int scrollHeight = [[webViewObj stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight"] intValue];

用于将网页滚动到特定偏移量:

[webViewObj stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.body.scrollTop =%d",scrollHeight]];