如何实现循环UIScrollView?

发布于 2024-09-13 07:23:25 字数 77 浏览 0 评论 0原文

如何实现循环UIScrollView?也就是说,当您滚动到最左边的项目时,UIScrollView 将显示最右边的项目。任何帮助将不胜感激。

How to implement a cyclic UIScrollView? That is to say, when you scroll to the very left item then the UIScrollView will show the very right one. Any help would be appreciate.

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

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

发布评论

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

评论(1

不知所踪 2024-09-20 07:23:25

当然,你需要三视图。在任何给定时间,您都有左视图、右视图和当前视图。

这需要通过 UIScrollViewDelegate 通知每个移动。

如果您检测到向右移动,则释放左侧,使左侧 = 当前,当前 = 右侧,然后创建一个新的右侧。

如果您检测到向左移动,则释放右侧,使右侧 = 当前,当前 = 左侧,然后再向左移动。

一般来说,任何与当前页面相差超过一页的视图都是不需要的。所以总共只需要三页。

当然,您还需要操纵 UIScrollView 的位置,以便可以进行移动 - 最终结果是您没有移动,尽管看起来像移动了。当您完成滚动并根据左/当前/右随机播放更改视图时,您

  [self scrollRectToVisible:(middle frame) animated:NO];

总是会看到相同的实际页面,每侧一页。当滚动发生时,看起来用户可以继续循环滚动 - 但在每个页面勾选之后,视图会被打乱,滚动视图中的位置被设置回中间,用户可以再次滚动。

回到开始,只需使用与您正在使用的任何数据结构另一端的任何对象相关的视图 - 因此,如果 current = [(NSArray)data lastObject] then <代码>右 = [(NSArray)数据对象AtIndex:0]。

Sure, you need three views. At any given time you have a left view, a right view and a current view.

This requires notification of each movement through the UIScrollViewDelegate.

If you detect that you moved right, you free left, make left = current, current = right, and make a new right.

If you detect that you moved left, you free right, make right = current, current = left, and make a new left.

Generally speaking, any view that is more than one page away from current is not required. So you need only three pages in total.

Of course you also need to manipulate the position of the UIScrollView so you can make the movements - the net result is you don't move although it looks like you have. When you have done the scroll, and altered the views according to the left/current/right shuffle - you do

  [self scrollRectToVisible:(middle frame) animated:NO];

so that you are always looking at the same actual page, with one page each side of it. When the scroll happens it looks like the user can keep scrolling around in a loop - but after each page ticks over, the views are shuffled, the position within the scroll view gets set back to the middle and the user can scroll again.

Getting back to the start is simply a matter of using the view related to whatever object is at the other end of whatever data structure you are using - so if current = [(NSArray)data lastObject] then right = [(NSArray)data objectAtIndex:0].

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