UICollectionView水平连续循环 [英] UICollectionView horizontal continuous loop

查看:157
本文介绍了UICollectionView水平连续循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个UICollectionView,每个单元格都有自定义UIViews。 UIView占据整个屏幕,您可以水平导航到4个不同的UIView /单元格中的每一个。这一切都很好,并使用寻呼机来指示您所在的集合视图的哪个页面。

So I have a UICollectionView with custom UIViews for each cell. The UIView takes up the whole screen and you can horizontally navigate to each of the 4 different UIView/cells. This all works fine and uses a pager to indicate which page of the collectionview you are on.

我已经浏览了谷歌之类的东西,看看我是否可以将它转到导航过去最后一个单元格后循环回到开头。例如:

I have looked around google and the like to see if I could get it to loop back to the beginning after you navigate passed the last cell. So for example:

我从第3个单元格开始,导航到第4个单元格,然后当我向右滑动时,它将返回到第一个单元格(寻呼机将反映你在第一页)并继续从那里开始。

I start at the 3rd cell, navigate to the 4th, then when i swipe to the right, it will go back to the first cell (pager will reflect that you are on the first page) and continue on from there.

这很容易吗?或者我错过了什么?

Is this easy to do? Or am I missing something?

谢谢,
杰克

推荐答案

您只需要3个UIViews,将图像保持在当前视图的左侧,图像保存在当前视图的右侧,中间视图,即当前在屏幕上的图像。

You only need 3 UIViews, to hold the image to the left of your current view, the image to the right of the current view, and the middle view, the one that is currently onscreen.

所以我们假设我们有UIImages ABCD和UIViews 1 2和3

So lets say we have UIImages A B C D and UIViews 1 2 and 3

我们正在查看视图2,图像B.我们将图像A,页面右侧转换为图像C。

We are looking at View 2, image B. Page left will take us to image A, page right to image C.

当向左/向右滑动时,视图3成为带有图像C的屏幕视图。当分页停止时,你交换视图内容,所以用户实际上再次看到中间的UIView2,图像C.视图1有图像B,视图3有图像D.

As you swipe left/ page right, view 3 becomes the onscreen view with image C. When paging comes to rest, you swap the views contents around so the user is actually looking at the middle UIView2 again, with image C. View 1 has image B, view 3 has image D.

滚动再一次,并做同样的洗牌。现在你已经

Scroll right again, and do the same shuffle. Now you have

View 1 -> image C
View 2 -> image D
View 3 -> image A

下一页右边

View 1 -> image D
View 2 -> image A
View 3 -> image B

等等,无论如何无限制地进行广告

so on, ad infinitum in either direction

从2011年开始,这个主题有一个很好的WWDC视频。值得挖掘出来。 这是UIScrollView演示视频文档为PDF )您不需要收集视图来执行此操作,但您没有理由不这样做...

There is a nice WWDC video on this subject from 2011. Its worth digging out. It's the UIScrollView demo video (Documentation as PDF) You don't need Collection Views to do this, although there is no reason why you shouldn't...

这篇关于UICollectionView水平连续循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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