UIScrollView问题
我正在构建一个使用 UIScrollView 的应用程序。我需要检测用户何时到达内容末尾。当谈论左侧时它效果很好。这是我的代码:
if([scrollView contentOffset].x < -120.0f)
[self prev:nil];
我希望我能对右侧说同样的话。 NSLog 解决了我的问题
NSLog(@"Off %f, content %f", [scrollView contentOffset].x, [scrollView contentSize].width);
当我滚动到内容的限制时,我看到:
2011-03-16 14:24:40.920 Digibi[1774:707] Off 627.000000,内容 1106.286011
有谁知道一个好的解决方案吗?
提前致谢。
I'm building an application that uses an UIScrollView. I need to detect when the user reaches the end of the content. It works fine when talking about the left side. Here's my code:
if([scrollView contentOffset].x < -120.0f)
[self prev:nil];
I wish I could say the same about the right side. A NSLog releaved me the problem
NSLog(@"Off %f, content %f", [scrollView contentOffset].x, [scrollView contentSize].width);
When I scroll to the limit of the content, I see this:
2011-03-16 14:24:40.920 Digibi[1774:707] Off 627.000000, content 1106.286011
Does anyone knows a good solution for that?
Thanks in advanced.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
内容偏移量是从滚动视图内容的左边缘开始测量的。在本例中,内容宽度和内容偏移之间的差异约为 480 像素,大概是滚动视图的宽度。当您需要检查右边缘在哪里时,只需将滚动视图边界的宽度添加到内容偏移量即可。
The content offset is measured from the left edge of the scroll view's content. In this case, the difference between the content width and the content offset is approximately 480 pixels—presumably the width of your scroll view. Just add the width of the scroll view's bounds to the content offset when you need to check where the right edge is.