🎉 🎉 🎉 🎉 🎉 让你轻松实现类似支付宝的拖拽重排功能, 支持各种自定义操作。
iOS8+
,具体可查看代码。pod 'BMLongPressDragCellCollectionView'
pod install
#import "BMLongPressDragCellCollectionView.h"
clone https://github.com/liangdahong/BMLongPressDragCellCollectionView.git
」BMLongPressDragCellCollectionView
文件夹下的全部内容拖拽到你的项目。BMLongPressDragCellCollectionView
是继自 UICollectionView
,其使用方式和 UICollectionView
一致,只需要把 UICollectionView
修改为 BMLongPressDragCellCollectionView
即可【支持 Xib,StoryBoard】。UICollectionViewDataSource
换为 BMLongPressDragCellCollectionViewDataSource
UICollectionViewDelegateFlowLayout
换为 BMLongPressDragCellCollectionViewDelegate
。NSArray< NSArray<id> *> *
的数据结构是因为内部要对 cell
【数据源】做排序处理。- (NSArray< NSArray<id> *> *)dataSourceWithDragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView;
如下:
- (NSArray<NSArray<id> *> *)dataSourceWithDragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView {
return self.dataSourceArray;
}
- (void)dragCellCollectionView:(BMLongPressDragCellCollectionView *)dragCellCollectionView newDataArrayAfterMove:(nullable NSArray< NSArray<id> *> *)newDataArray;
如下:
- (void)dragCellCollectionView:(BMLongPressDragCellCollectionView *)dragCellCollectionView newDataArrayAfterMove:(nullable NSArray< NSArray<id> *> *)newDataArray {
self.dataSourceArray = [newDataArray mutableCopy];
}
Xib
或者 StoryBoard
中使用Xib
或者 StoryBoard
中只需要上面的 3 步
就可以让你的 UICollectionView
完美支持拖拽重排了。3 步
就可以让你的 UICollectionView
完美支持拖拽重排了。如果要做一些自定义的操作可以通过设置 BMLongPressDragCellCollectionView
的相关属性或者实现一些特定的协议方法来处理,可查看 BMLongPressDragCellCollectionView
的头文件和 BMLongPressDragCellCollectionViewDelegate
与 BMLongPressDragCellCollectionViewDataSource
协议。
BMLongPressDragCellCollectionView is released under the MIT license. See LICENSE for details.