Objective-C:没有 pagingEnabled 的无尽 UIScrollView
在我的 iPhone 应用程序中,有一个滚动视图 pagingEnabled=NO
,它最多可以包含 200 个子视图 (150 x 150),挑战是进行延迟加载并模拟水平方向上的无限滚动(无弹跳)。
对于这个请求有解决方案或替代方案吗?
In my iPhone app there is a scrollview pagingEnabled=NO
which can contain up to 200 subviews (150 x 150) and the challenge is to do lazy loading and simulate endless scrolling (without bouncing) in horizontal directions.
Is there a solution or an alternative for this request?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Apple 的示例代码项目之一演示了滚动视图的延迟加载: PageControl。
为了伪造无休止的滚动,我的建议是让你的滚动视图一开始就非常宽,比普通人在一组滚动行为中滚动的宽度要宽。然后在您的委托方法中
-scrollViewDidEndScrollingAnimation:
、-scrollViewDidEndDragging:willDecelerate:
和-scrollViewDidEndDecelerating:
中,其中一个或多个将在用户完成滚动后,将您的内容重新定位到滚动视图的中心,并更新您的contentOffset
点而不使用动画。为了使其在视觉上工作,您还需要禁用水平滚动条。您还需要考虑如何使用此方法确定在特定
contentOffset
处绘制哪个视图,因为您无法仅将contentOffset.x
除以不再滚动视图的边界来找出您所在的位置。Lazy loading of a scroll view is demonstrated in one of Apple's sample code projects: PageControl.
To fake endless scrolling what I'd suggest is to make your scroll view very wide to begin with, wider than an average person would scroll in one set of scrolling behaviors. Then in your delegate methods
-scrollViewDidEndScrollingAnimation:
,-scrollViewDidEndDragging:willDecelerate:
and-scrollViewDidEndDecelerating:
, one or more of which will be called after the user is done scrolling, reposition your content to exist in the center of the scroll view and update yourcontentOffset
point without animating.For that to work visually you would need to also disable the horizontal scroller. You'll also need to consider how to determine what view to draw at a particular
contentOffset
with this method since you won't be able to just divide thecontentOffset.x
by the scroll view's bounds anymore to find out where you are.你好,我找到了方法。
我有一个包含所有子视图的主数组(在我的例子中它们是图像,所以我存储名称)。
滚动视图只有 3 个子视图:左视图、当前视图、右视图。
分页已启用,因此用户在任何时候都无法向左/向右旋转多个视图。
我所做的是:
1) 跟踪他在主阵列上的当前位置。如果他向左移动,则减一;右加一。像这样:
2)用户移动后,我重新加载3个新图像,像这样:
3)最后再次将滚动视图重新居中到中心视图:
希望这会有所帮助,尽管“有计划的人”是克拉克先生,谁指路了。
贡索
Hello I found the way to do it.
I have a master array with all the subviews (in my case they are images, so I store the names).
The scrollview only has 3 subviews: left, current, right.
Paging is enabled, so the user cant really spin more that one view left/right at any time.
What I do is:
1) track his current position on the master array. If he moves left, subtract one; right add one. Like this:
2) after the user moves, I reload 3 new images, like this:
3) Finally re-center the scroll view to the center view again:
Hope this helps, although "the man with the plan" is Mr. Clark, who pointed the way.
Gonso
Matt Gallagher 有一篇博客文章,其中描述了此问题的解决方案确切的问题。我用过它,效果很好。
它的工作原理是在子视图周围打乱并在必要时重置其内容。我用它来显示闪存卡,其中可能有 3 到 3,000 个项目。尽管它现在已设置为分页,但我相信您可以让它与常规滚动一起使用。
Matt Gallagher has a blog post which describes a solution to this exact problem. I've used it and it works great.
It works by shuffling around the child views and reseting their content when necessary. I used this for displaying flash cards, where there could be anywhere from 3 to 3,000 items. Although it's set up right now for paging, I'm sure you could get it to work with regular scrolling.