views:

19

answers:

2

I have an ebook style iPhone app that allows users to read a book. I have it setup so that when they leave the app, it remembers what page they were on, but not the exact spot on the page (the page can scroll quite a bit).

I am using NSUserDefaults to get me back to the page, I was wondering though if anyone had any ideas about how I might go about capturing the location they are on the page...

Would there be some way to capture y coordinate locations? Is that the right direction? What do you think?

Thanks!!

A: 

UIScrollView has a contentOffset property that returns a CGPoint (which is just a struct that has x and y coordinates). For example:

CGPoint p = scrollview.contentOffset;
// save p, or just p.y, to NSUserDefaults
// ...

// and then next time:
CGPoint p;
p.x = 0;
p.y = getYourYValueFromNSUserDefaults();
[scrollview setContentOffset:p animated:NO];
Jesse Beder
A: 

Sure...

Save [scroll contentOffset]; returns CGPoint, and then set it on launch: [scroll setContentOffset:CGPoint animated:YES];

From memory, so check syntax.

Jordan
Thanks for your answer. I am wondering now where the best place to save that point just before the app closes. Just like there is viewDidLoad for when a view has loaded, is there a built in method where it would be optimal for me to capture the point when the view is in it's final state andbready to close? Probably a dumb question, but I can't figure it out
George H.
In your AppDelegate there is a method, (void)applicationWillTerminate (again from memory, so check syntax).
Jordan