views:

419

answers:

2

Hello

I would like to add an URL/google bar on top of my webview, and access it by scrolling up my web page exactly as Safari do. To do this, I would detect when the user is scrolling the page, and more over when the scroll reaches the top.

But I really don't know how.

An idea ? Thanx a lot.

Martin

A: 

Yep, you want to implement the UIScrollViewDelegate for your UIWebView.

David Sowsy
But UIWebView does not implement the UIScrollViewDelegate !There are already some discutions about, and they say that it's only possible with javascript... (http://stackoverflow.com/questions/1604795/scrolloffset-in-uiwebview)
Martin
+1  A: 

Hi ,

You can use the following methods to solve your problem.

For getting the pageOffset:

int pageYOffset = [[webViewObj stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];

For getting the total scroll height of a webpage:

int scrollHeight = [[webViewObj stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight"] intValue];

For scrolling the webpage to a particular offset:

[webViewObj stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.body.scrollTop = %d",scrollHeight ]];

Biranchi