How can I get current scroll position on UIWebView
-
16-09-2019 - |
Question
I have a UIWebView And how can i get It's scroll position ?
I know, that UIWebView has a UIScroller subview. But I can't get offset of this UIScroller (((
Solution
This trick works for me.
UIWebView *webView;
int scrollPosition = [[webView stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];
Please refer to the answer given by zamber for a better solution on iOS 5 and later. My answer was for iOS 4 and below.
OTHER TIPS
There is a better and more resource-friendly way to do this:
UIWebView *webView;
CGFloat offset = webView.scrollView.contentOffset.y;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow