开发者

Use NSUserDefaults to get to a certain position in a UIScrollView

开发者 https://www.devze.com 2023-01-22 17:16 出处:网络
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 ca

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 NSUser开发者_JAVA技巧Defaults 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!!


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];


Sure...

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

From memory, so check syntax.

0

精彩评论

暂无评论...
验证码 换一张
取 消