我需要将一个单元格从CollectionView
一个拖放到
CollectionView
两个。一个 CollectionView 内的拖放是没有问题的,但我怎样才能将 Cell 从 CollectionView One 移到 CollectionView 2?
有任何想法吗?任何已经解决了这个问题的项目或框架?感谢您的帮助!
我需要将一个单元格从CollectionView
一个拖放到
CollectionView
两个。一个 CollectionView 内的拖放是没有问题的,但我怎样才能将 Cell 从 CollectionView One 移到 CollectionView 2?
有任何想法吗?任何已经解决了这个问题的项目或框架?感谢您的帮助!
https://github.com/Ice3SteveFortune/i3-dragndrop Check this out - its a helper I'm working on to achieve just that. It also supports tableviews
UPDATE
I've recently released the second version of this codebase, called BetweenKit. Its now a fully-fledged drag-and-drop framework.
Hope it proves useful !
当您从第一个集合视图中选择单元格时,将其从此集合视图中删除,创建一个新视图作为该单元格的副本,并将其作为超级视图的子视图放在所有视图之上。使用平移手势使该视图可移动。一旦你“放下”这个中间单元,检测它的位置并将它添加到当前的集合视图中。
好的,这是以下示例中最简单的流程:
UIGestureRecognizer
为每个添加UICollectionView
。 用一种方法连接每个手势识别器:
@IBAction func longPressGestureChanged(recognizer: UILongPressGestureRecognizer) { ... }
在为每个UIViewController
添加:@IBOutlet
UICollectionView
@IBOutlet var collectionViewGreen: UICollectionView!
@IBOutlet var collectionViewYellow: UICollectionView!
实现手势识别器方法来检测变化:
@IBAction func longPressGestureChanged(recognizer: UILongPressGestureRecognizer) {
let globalLocation = recognizer.locationInView(view)
if CGRectContainsPoint(collectionViewGreen.frame, globalLocation) {
//you cover green collection view
let point = view.convertPoint(globalLocation, toView: collectionViewGreen)
if let indexPath = collectionViewGreen.indexPathForItemAtPoint(point) {
//you cover cell in green collection view
} else {
//you do not cover any of cells in green collection view
}
} else if CGRectContainsPoint(collectionViewYellow.frame, globalLocation) {
//you cover yellow collection view
let point = view.convertPoint(globalLocation, toView: collectionViewYellow)
if let indexPath = collectionViewYellow.indexPathForItemAtPoint(point) {
//you cover cell in yellow collection view
} else {
//you do not cover any of cells in yellow collection view
}
} else {
//you do not cover any of collection views
}
}