How to show UIWebView's scroll indicators

女生的网名这么多〃 提交于 2019-12-22 04:16:12

问题


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?


回答1:


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];



回答2:


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
}


来源:https://stackoverflow.com/questions/1188752/how-to-show-uiwebviews-scroll-indicators

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!