/BMDragCellCollectionView

UICollectionViewCell拖拽重排,Drag,DragAndDrop,LongPressGestures,LongPressGesturesDrag,LongPressGesturesDragAndDrop,UICollectionView,UICollectionViewCell,UICollectionViewCellDrag,UICollectionViewCellDrag,UICollectionViewCellRearrangement,UICollectionViewRearrangement,iOS

Primary LanguageObjective-CMIT LicenseMIT

BMDragCellCollectionView

Version Support Weibo GitHub stars

写在前面

最近公司准备做一个类似支付宝UICollectionViewCell拖拽重排的功能,UICollectionViewCell的任意拖拽排列,支付宝最新的版本已去掉了任意拖拽功能,而只是对常用功能进行拖拽重排,没有出现超出屏幕的情况。个人感觉应该更好,毕竟太多功能去拖拽重排对用户来说是一个特别大的工作量,只需把常用功能提即可。相应的功能点还是在对应的分组里,至于我们的需求暂时不怎么清楚,使用还是研究下任意拖拽吧。

未来计划

  1. Demo及文档完善。
  2. 支付宝拖拽效果实现。
  3. 今日头条频道拖拽重排效果实现。
  4. 看荐拖拽重排效果实现及优化。ps:看荐的拖拽重排发现一个bug,哈哈。
  5. 其他

效果图

效果1

效果1

须知

BMDragCellCollectionView 基于 Xcode 8.2.1 , iOS 6+ ARC ,请使用最新正式版来编译BMDragCellCollectionView ,旧版本的Xcode 有效,但不保证会出现一些兼容性问题。

开源不易,来个star鼓励下吧

集成

CocoaPods

推荐使用 CocoaPods 安装。

  1. Podfile 中添加 pod 'BMDragCellCollectionView', '1.0.2'
  2. 执行 pod installpod update
  3. 使用的地方导入 "BMDragCellCollectionView.h"
  4. 如果无法找到 BMDragCellCollectionView 可用 pod setuprm ~/Library/Caches/CocoaPods/search_index.jsonpod search BMDragCellCollectionView

手动安装

  1. 通过 Clone 或者 download 下载BMDragCellCollectionView 文件夹内的所有内容。
  2. 将 BMDragCellCollectionView 内的源文件添加(拖放)到你的工程。
  3. 导入 "BMDragCellCollectionView.h"

使用说明

  • 在需要使用长按拖拽UICollectionView 的地方使用BMDragCellCollectionView代替,用法和UICollectionView一样。
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
BMDragCellCollectionView *collectionView = [[BMDragCellCollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) collectionViewLayout:layout];
collectionView.delegate = self;
collectionView.dataSource = self;
[self.view addSubview:collectionView];
  • 实现 BMDragCollectionViewDataSource协议的如下方法

此协议用于在交换时获取数据源,内部做数据源操作。

- (NSArray *)dataSourceWithDragCellCollectionView:(BMDragCellCollectionView *)dragCellCollectionView {
    return self.dataSource;
}
  • 实现 BMDragCellCollectionViewDelegate协议的如下方法

此协议用于在在内部处理好数据源时通知使用者更新数据源。

- (void)dragCellCollectionView:(BMDragCellCollectionView *)dragCellCollectionView newDataArrayAfterMove:(NSArray *)newDataArray {
    self.dataSource = [newDataArray mutableCopy];
}

期待

  • 如果在使用过程中遇到BUG,希望您能Issues我。

版本历史

v1.0.2

v1.0.1

v1.0.0

MIT

BMDragCellCollectionView 使用 MIT 许可证,详情可见 LICENSE 文件