In IOS, how to know whether the UIWebView's scroller is at the top?

203 Views Asked by At

I am making an iOS application which has an action like this.

http://www.flickr.com/photos/71607441@N07/6721920809/ is a full screen web view. when the scroller is on top, If I touch the webview, It goes down and cover half of the screen. (If the scroller is not on the top, the action won't do)

http://www.flickr.com/photos/71607441@N07/6721847313/ like this.

I am confused how to know where the scroller position is.

UIWebView has few properties, and I guess I need to embed the UIWebView in a UIScrollView, or Do I have to use javascript?

1

There are 1 best solutions below

0
On

Not sure what you're trying to do exactly, but if you're trying to move the UIWebView down as a whole I'd add it to a UIView and then put the UIView into a UIScrollView. That will keep it in a fixed position relative to any other elements you add to the UIView. You may wind up with some odd behaviors though as UIWebView already contains a UIScrollView and the touch events will have to be handled between the two correctly.

If you're trying to find out how far the web view is scrolled down "inside" itself, you can use this little hack:

NSString *scrollTopStr = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollTop;"];    
NSLog(@"scroll top: %@", scrollTopStr);