Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get current scroll position on UIWebView

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

like image 823
oxigen Avatar asked Apr 24 '09 15:04

oxigen


2 Answers

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

like image 178
zamber Avatar answered Oct 18 '22 04:10

zamber


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.

like image 42
Chris Lundie Avatar answered Oct 18 '22 02:10

Chris Lundie