If you have an iPhone application that makes use of a long UIWebView, alot of times you’ll want it to stay scrolled to wherever the user has scrolled to, even if they restart the application. This means that you need to find out where the user is scrolled in the document when the application closes, store that information, and then scroll back there when it opens again.
You can use
Then, when you want to go back to that point, call the
scrollTo (x, y). It’s important that you pass it both x and y parameters, even if x is 0, or it won’t work. So
scrollTo(0, 500) would scroll you 500 pixels down the page. And of course, you have to call this after your
UIWebView has actually loaded the page, no just when your application starts.
Here’s some sample code for getting the position, saving it, and then reloading it. This code would need to be in the class that is your app delegate, as well as the . Also, make sure you define an NSInteger in your header file, like
And that should give you a UIWebView that stays in place even when the user restarts the application.