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.
- RT @asmallteapot: “Show my timer.” http://t.co/13OxVJ9cGz 4 days ago
- #ff @JossActual I know it's not Friday. I really do... 5 days ago
- RT @rosspruden: "63% had never backed a project before." http://t.co/rFmBJWBg9Q Big Kickstarters lead to the pie *expanding*, not contracti… 1 week ago
- They said: "receive a free orchid plant" I heard: "receive a free organ transplant" #strangefreebies 1 week ago
- Stop trying to think outside the box: instead, reinvent the corrugated cardboard industry. #lifetip 2 weeks ago