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

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

问题描述

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

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个UIView,分别保存当前view左边的图片,当前view右边的图片,中间view,当前在屏幕上的那个.

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 A B C D 和 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天全站免登陆