如何实现循环UIScrollView? [英] How to implement a cyclic UIScrollView?

查看:144
本文介绍了如何实现循环UIScrollView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何实现循环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.

推荐答案

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

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

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

This requires notification of each movement through the UIScrollViewDelegate.

如果您检测到您向右移动,则向左移动,使left = current,current = right,并使其成为新的权利。

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.

当然你还需要操纵UIScrollView的位置,这样你才能做出动作 - 最终的结果就是你不要虽然它看起来像你有,但移动。当你完成了滚动,并根据左/当前/右边的shuffle改变了视图 - 你做了

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.

回到起点只是使用与您正在使用的任何数据结构的另一端的任何对象相关的视图 - 所以如果 current = [(NSArray)data lastObject] 然后 right = [(NSArray)data objectAtIndex:0]

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

这篇关于如何实现循环UIScrollView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆