如何在UICollectionView for iOS Objective-c中创建无限滚动 [英] How can I create Infinite Scrolling in UICollectionView for iOS Objective-c

查看:131
本文介绍了如何在UICollectionView for iOS Objective-c中创建无限滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在我的 UICollectionView 中创建无限滚动?

How To Create Infinite Scrolling in my UICollectionView?

附加屏幕截图:

现在我的 NSArray

NSArray* nameArr = [NSArray arrayWithObjects: @"0", @"1", @"2", @"3", @"4", nil];

我想在collectionView中创建无限滚动完成后的数组一次又一次地重复所有单元格。

左右两侧都需要滚动无限。

如果是,那么我该如何实现请在objective-c中给出一个参考。

If yes, then how can I implement please give a reference in objective-c.

谢谢!提前

推荐答案

我们可以使用PMCircularCollectionView来做到这一点。

We can do this using "PMCircularCollectionView".

PMCircularCollectionView 是UICollectionView的子类,可在水平或垂直方向无限滚动。 PMCircularCollectionView 还包括一个子类,它自动将最近的单元格居中。滚动后集合视图的中间位置。

PMCircularCollectionView is a subclass of UICollectionView that scrolls infinitely in the horizontal or vertical direction. PMCircularCollectionView also includes a subclass which automatically centers the cell nearest to the middle of the collection view after scrolling.

演示PMCircularCollectionView

为了实现无限滚动,PMCircularCollectionView采用了这篇博客文章中描述的技术,该技术将内容大小倍增,从而索引路径的数量。因此,当少于16个项目返回到-collectionView:numberOfItemsInSection:delegate方法时,dataSource和delegate方法可以传递item == 15的索引路径。如上例所示,调用-normalizeIndex:将项索引更改为正确的值。

To achieve infinite scrolling, PMCircularCollectionView employes a technique described in this blog post which multiplies the content size and consequently the number of index paths. Thus, it is possible for dataSource and delegate methods to pass an index path with item == 15, when less than 16 items were returned to the -collectionView:numberOfItemsInSection: delegate method. As seen in the examples above, call -normalizeIndex: to change the item index to the correct value.

这篇关于如何在UICollectionView for iOS Objective-c中创建无限滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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