【发布时间】:2017-05-11 14:25:42
【问题描述】:
我正在 iOS Xcode 8.3.2 Swift 3.1 中创建一个屏幕,上面有一个水平滚动的 UICollectionView 和一行图像。问题是,我曾认为“自动重新排序”功能是 UICollectionView 的一部分,而实际上它只在 UICollectionViewController 中实现。因为我只想滚动屏幕的一部分,所以我不相信我可以使用集合视图控制器——在这种情况下集合视图总是全屏的,对吧?使用控制器,我发现了installsStandardGestureForInteractiveMovement,它自动实现了手势识别器。
我希望在 UIViewController 上的集合视图中具有相同的功能。但是,我不知道需要捕获哪些手势来实现单元格重新排序。集合视图本身是否内置了任何拖动重新排序“魔法”?有没有办法我可以使用控制器,而不是让集合视图全屏显示?
我已经实现了以下方法来进行数据的实际移动,但我不确定要设置哪个手势识别器。
func collectionView(_ collectionView: UICollectionView,
moveItemAt sourceIndexPath: IndexPath,
to destinationIndexPath: IndexPath) {
let cellToMove = promoPages.remove(at: (sourceIndexPath as NSIndexPath).row)
promoPages.insert(cellToMove, at: (destinationIndexPath as NSIndexPath).row)
}
【问题讨论】:
-
谢谢,@user2215977。通过对 Swift 3.1 的一些调整,我得到了它的工作。我想我也找到了那篇文章,但看到对“...控制器”的引用并停止阅读。
标签: ios swift uicollectionview uigesturerecognizer