views:

29

answers:

1

I need to detect if the scroll bar is visible in the UIWebView, how do I do this? My first attempt was:

int scrollHeight = [[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight"] intValue];
if(scrollHeight > [webView frame].size.height)
    NSLog(@"Scrollbar is visible");

But the scrollHeight is always a way larger than the webView height.

A: 

Try the following (no private APIs):

for (id subView in [webView subviews]) {
    if ([subView respondsToSelector:@selector(flashScrollIndicators)]) {
        [subView flashScrollIndicators];
    }
}

This doesn't assume anything about the internal UIWebView hierarchy, but just if there happens to be a subview that responds to flashScrollIndicators they will be flashed. ;)

MattLeff
yes, I've seen this before, but I need to create a custom way to visualize this (not by flashScrollIndicators)
Konstantin
Check this out: http://stackoverflow.com/questions/745160/how-to-determine-uiwebview-height-based-on-content-within-a-variable-height-uita/751326#751326
MattLeff