双向无限 UIScrollView
我想创建一个无限滚动视图(就像老虎机),但没有分页。当用户向下滚动时,很容易我只需要增加 contentSize 和滚动视图无休止地滚动:
- (void)scrollViewDidScroll:(UIScrollView *)theScrollView {
theScrollView.contentSize = CGSizeMake(45, theScrollView.contentSize.height+45);
}
但是当用户向上滚动时如何创建相同的效果?我尝试使用 contentInset 但随后 contentOfsset 没有更新,我最终出现了奇怪的行为。
你知道我怎样才能做到这一点吗?
I would like to create an infinite scrollView (like a slot machine), but without paging. When the user scrolls down, it's easy i just have to increase the contentSize and the scrollView scroll endlessly :
- (void)scrollViewDidScroll:(UIScrollView *)theScrollView {
theScrollView.contentSize = CGSizeMake(45, theScrollView.contentSize.height+45);
}
But how can i create the same effect when the user scrolls upward ? I tried to play with the contentInset but then the contentOfsset doesn't get updated and i end up having weird behaviour.
Do you have any idea how i could achieve that ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我需要相同的,所以我创建了这个: http: //dev.doukasd.com/2011/04/infinite-scrolling-dial-control-for-ios/
看看视频,我相信这就是您要找的。包含源代码。
I needed the same, so I created this: http://dev.doukasd.com/2011/04/infinite-scrolling-dial-control-for-ios/
Have a look at the video, I believe it's what you're looking for. Source code is included.
我开发了这种滚动视图。它可以无限滚动。
您可以在github上查看: https://github.com/quangrubify/InfiniteUITableView
I have developed this kind scroll view. It can scroll infinite.
You can check on github: https://github.com/quangrubify/InfiniteUITableView
我认为你应该向我们提供有关该问题的更多详细信息。你希望用户向上滚动时看到什么内容?您在scrollViewDidScroll方法中增加了contentSize,但您没有检查contentOffset,因此每当用户滚动scrollView时,内容就会更大(无论哪种方式,如果允许,甚至水平滚动)。由于 contentOffset 已经为 0,因此用户无法向上滚动,因为滚动视图无法显示任何内容。
我不知道你的scrollView的内容,但我已经实现了水平无限滚动。详情请参见:https://stackoverflow.com/a/12856174/936957
PS:不要使用“幻数” ”,这是一个更好的选择:
I think you should give us more details about the issue. What content do you want the user to see when he is scrolling upwards? You increase the contentSize in scrollViewDidScroll method, but you are not checking the contentOffset, so the contentWill be bigger whenever the user scrolls the scrollView (either way, even horizontal if allowed). Since the contentOffset is already at 0, the user cant scroll upwards because there is nothing that the scroll view can show.
I dont know the content of your scrollView, but I have implemented infinite scrolling horizontally. For details, see: https://stackoverflow.com/a/12856174/936957
PS: Do not use "magic numbers", this is a better alternative: