views:

300

answers:

2

Hi does anybody know how I can programatically scroll a UIWebView in Objective-C (iPhone SDK)?

The only solution I can think of is to put it inside a UIScrollView and programatically scroll that, however this presents the problem that the web view is often the wrong size and therefore the bottom of the page is cut off when scrolling. I have no idea how to programatically change the size of a web view to fit its content either... so far I have:

UIView *webDocView = webView.subviews.lastObject; webView.frame = CGRectMake(webView.frame.origin.x, webView.frame.origin.y, webView.frame.size.width, webDocView.frame.size.height);

But for some reason this will not work

Should I persue the solution of using a ScrollView... or is there a better way to do this?

Sorry if this is presented confusingly - I'm relatively new to Objective-C

Any help is greatly appreciated :)

+2  A: 

UIWebView doesn't have any properties that specify its position on the document it is rendering. You likely need to do this through Javascript, if you want the animated feel of it take a look at this. http://www.learningjquery.com/2007/09/animated-scrolling-with-jquery-12

Flash84x
Thanks very much for the info...So I guess I would just substitute the Java script in the page you sent me into this:NSString *yourScript = [NSString stringWithFormat:@"javascript_method();"]; NSString* responseJS = [webView stringByEvaluatingJavaScriptFromString:yourScript];?(from the "duplicate" post page)Thanks :)
Karl Taylor
You're welcome, you can mark this as the answer to give me some points :)
Flash84x
A: 

Apple says: "You should not embed UIWebView objects in UIScrollView object. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled." This probably has a lot to do with instances of both UIWebView and UIScrollView being scrollable and the interaction of two scrolling requests is too much.

SpecialK