UIScrollView with“Circular”滚动 [英] UIScrollView with "Circular" scrolling

查看:201
本文介绍了UIScrollView with“Circular”滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的UIScrollView中进行循环滚动,但不成功。



我想做什么:
如果uiscrollview到达结束应该移动到开始
如果uiscrollview在开始和回来,它应该移动到结束



追加scrollview是不是好的方式在我的情况(其他方法应该getpage id)



有任何想法吗?

解决方案

我已实施此方法,但需要启用分页功能。假设你有五个元素 A,B,C,D和E 。设置视图时,将最后一个元素添加到开头,将第一个元素添加到结尾,然后调整内容偏移量以查看第一个元素,例如 E,[A],B, C,D,E,A 。在UIScrollViewDelegate中,检查用户是否到达任何一端,并将偏移而不移动到另一端。



想象一下[ ]表示显示的视图:

  E,A,B,C,[D],E,A 

用户向右滑动

  E,A,B,C,D,[E],A 

/ p>

  E,A,B,C,D,E,[A] 
/ pre>

然后,自动将内容偏移设置为第二个元素

  E,[A],B,C,D,E,A 

  E,A,[B],C,D,E, A 






/ h2>

我已上传此算法的完整实现。这是一个非常复杂的类,因为它也有点击选择,无限循环滚动和单元格重用。您可以使用该代码,修改它或提取您需要的代码。最有趣的代码在 TCHorizo​​ntalSelectorView 中。



链接到文件



尽情享受吧!






更新2



UICollectionView 推荐的方式来实现这个和它可以用来获得非常相同的行为。 本教程详细介绍了如何实现它。 / p>

I am trying to make "Circular" scrolling in my UIScrollView, but unsuccessful.

What I want to do: if uiscrollview reaches end, it should move to start if uiscrollview at start and moving back, it should move to end

Appending scrollview isn't good way in my situation (other methods should get "page id")

Have you any ideas?

解决方案

I've implemented this method, but it requires paging enabled. Lets assume you have five elements A,B,C,D and E. When you set up your view, you add the last element to the beginning and the first element to the end, and adjust the content offset to view the first element, like this E,[A],B,C,D,E,A. In the UIScrollViewDelegate, check if the user reach any of the ends, and move the offset without animation to the other end.

Imagine the [ ] indicates the view being shown:

E,A,B,C,[D],E,A

User swipes right

E,A,B,C,D,[E],A

User swipes right

E,A,B,C,D,E,[A]

Then, automatically set the content offset to the second element

E,[A],B,C,D,E,A

This way the user can swipe both ways creating the illusion of an infinite scroll.

E,A,[B],C,D,E,A


Update

I've uploaded a complete implementation of this algorithm. It's a very complicated class, because it also has on-click selection, infinite circular scroll and cell reuse. You can use the code as is, modify it or extract the code that you need. The most interesting code is in the class TCHorizontalSelectorView.

Link to the file

Enjoy it!


Update 2

UICollectionView is now the recommended way to achieve this and it can be used to obtain the very same behavior. This tutorial describes in details how to achieve it.

这篇关于UIScrollView with“Circular”滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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