如何在我的应用程序中创建无限滚动UICollectionView
?
附截图:
Now my NSArray
is
NSArray* nameArr = [NSArray arrayWithObjects: @"0", @"1", @"2", @"3", @"4", nil];
我想在完成数组后在 collectionView 中创建无限滚动,一次又一次重复所有单元格。
需要向左和向右两侧滚动无限。
如果是的话,我该如何实现,请在objective-c中给出参考。
谢谢!!!提前
简单的方法是使用稳定的 CollectionViewLayout.
实现的基本原理是创建 UICollectionViewLayout 的子类并重写这些方法
override open func prepare(forCollectionViewUpdates updateItems: [UICollectionViewUpdateItem]) {
super.prepare(forCollectionViewUpdates: updateItems)
// there is possible to calculate a content offset the difference
// with the help layout attributes for each updated item or only visible items
self.offset = calculate(...)
}
override open func finalizeCollectionViewUpdates() {
super.finalizeCollectionViewUpdates()
self.offset = nil
}
override open func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
// there is necessary to add difference to/instead proposedContentOffset
if let offset = self.offset {
return offset
}
return proposedContentOffset
}
它允许在插入或删除发生时保持内容偏移。
然后你可以只在头部插入并删除尾部,反之亦然。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)