使用 NSUserDefaults 到达 UIScrollView 中的某个位置

发布于 2024-09-29 11:25:53 字数 226 浏览 0 评论 0原文

我有一个电子书风格的 iPhone 应用程序,允许用户阅读一本书。我对其进行了设置,以便当他们离开应用程序时,它会记住他们所在的页面,但不会记住页面上的确切位置(页面可以滚动相当多的距离)。

我正在使用 NSUserDefaults 让我返回页面,我想知道是否有人对我如何捕获它们在页面上的位置有任何想法...

是否有某种方法可以捕获 y 坐标位置?这是正确的方向吗?你怎么认为?

谢谢!!

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!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你怎么这么可爱啊 2024-10-06 11:25:53

UIScrollView 有一个 contentOffset 属性返回一个 CGPoint (这只是一个具有 x 和 y 坐标)。例如:

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

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];
夜雨飘雪 2024-10-06 11:25:53

当然...

保存[scroll contentOffset];返回 CGPoint,然后在启动时设置它: [scroll setContentOffset:CGPointAnimated:YES];

根据记忆,检查语法。

Sure...

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

From memory, so check syntax.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文