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 (((

Was it helpful?

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;

via http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebView_Class/Reference/Reference.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top