Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show UIWebView's scroll indicators

I have a UIWebView with some content and I need to make its scroll indicator visible for a short time (like [UIScrollView flashScrollIndicators]).

Any idea how to do this?

like image 387
oxigen Avatar asked Jul 27 '09 15:07

oxigen


People also ask

How do I check if a scroll is present?

To check if a scrollbar is present for an element, we can compare the scrollHeight value with its clientHeight value, both are in pixels.

How do I disable scrolling in WebView?

If you put a WebView in a ScrollView, set the android:isScrollContainer attribute of the WebView to "false" rather than setting android:scrollbars to "none". This has the effect of completely disabling the scroll handling of the webview and allows it to expand according to its content.

How do I enable scrolling in Visual Studio?

Open the Scroll Bars options page by choosing Tools > Options > Text Editor > All Languages > Scroll Bars.


2 Answers

Starting iOS 5.0 onwards, one can now customize the scrolling behavior of UIWebView by accessing the 'scrollview' property to achieve the desired functionality:

 [webView.scrollView flashScrollIndicators];
like image 79
Azeem Shaikh Avatar answered Oct 26 '22 22:10

Azeem Shaikh


There's no real way of doing this via a published API, however I think that in this case it's OK to guess the UIScrollView subview, so long as you make sure your application doesn't crash if you can't find the UIScrollView:

UIView* scrollView = [webView.subviews objectAtIndex:0];
if ([scrollView isKindOfClass:[UIScrollView class]) {
  [((UIScrollView*)scrollView) flashScrollIndicators];
} else {
  // If Apple changes the view hierarchy you won't get
  // a flash, but that doesn't matter too much
}

EDIT: The above will not work because the first subview of a UIWebView is a UIScroller, not a UIScrollView (my memory might be playing tricks on me). Perhaps try the following?

UIView* uiScroller = [webView.subviews objectAtIndex:0];
if ([uiScroller respondsToSelector:@selector(displayScrollerIndicators)]) {
  [((UIScrollView*)uiScroller) performSelector:@selector(displayScrollerIndicators)];
} else {
  // If Apple changes the view hierarchy you won't get
  // a flash, but that doesn't matter too much
}
like image 40
Nathan de Vries Avatar answered Oct 27 '22 00:10

Nathan de Vries