Skip to content

Latest commit

ย 

History

History
112 lines (78 loc) ยท 6.46 KB

README-English.md

File metadata and controls

112 lines (78 loc) ยท 6.46 KB

Introduction

  • This framework lets you easily add drag-and-drop rearrangement functionality similar to the Alipay app. It supports customization - check out the code for details. (iOS 8+)

Installation (CocoaPods)

pod 'BMLongPressDragCellCollectionView'
pod install
#import "BMLongPressDragCellCollectionView.h"

Installation (Manual)

  • Download the project: git clone https://github.com/liangdahong/BMLongPressDragCellCollectionView.git
  • Drag and drop all the contents of the BMLongPressDragCellCollectionView folder to your project

Usage

  1. BMLongPressDragCellCollectionView is a subclass of UICollectionView, so usage is the exact same as UICollectionView. Just replace UICollectionView with BMLongPressDragCellCollectionView in your Xib or Storyboard.
  2. Replace your UICollectionViewDataSource with BMLongPressDragCellCollectionViewDataSource
  3. Replace your UICollectionViewDelegateFlowLayout with BMLongPressDragCellCollectionViewDelegate
  4. Implement the data source method, which will be used internally to obtain the data source. This is required. The data structure of NSArray< NSArray<id> *> * is for the internal cell data source's sort processing.
- (NSArray< NSArray<id> *> *)dataSourceWithDragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView;

Implementation:

- (NSArray<NSArray<id> *> *)dataSourceWithDragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView {
    return self.dataSourceArray;
}
  1. Implement the proxy method, which is called when a cell is swapped with another cell. The latest data source needs to be saved outside (If there is an exchange, the data source is updated). This is also required.
- (void)dragCellCollectionView:(BMLongPressDragCellCollectionView *)dragCellCollectionView newDataArrayAfterMove:(nullable NSArray< NSArray<id> *> *)newDataArray;

Implementation:

- (void)dragCellCollectionView:(BMLongPressDragCellCollectionView *)dragCellCollectionView newDataArrayAfterMove:(nullable NSArray< NSArray<id> *> *)newDataArray {
    self.dataSourceArray = [newDataArray mutableCopy];
}

Usage screenshots

Xib or Storyboard

In a Xib or Storyboard, you only need the above 3 steps to make your UICollectionView support drag and drop rearrangement perfectly.

Programmatically

Programmatically, you only need the above 3 steps to make your UICollectionView support drag and drop rearrangement perfectly.

Customization

If you want to add custom behavior, you can set the relevant properties of BMLongPressDragCellCollectionView or implement some specific protocol methods (find them in the header file of BMLongPressDragCellCollectionView and the protocol of BMLongPressDragCellCollectionViewDelegate and BMLongPressDragCellCollectionViewDataSource)

Contact

  • Please raise an issue or make a PR
  • Check out our WeChat group

Other

  • A pure Swift rewrite is planned for August 5, 2020...

Credits

Tips

  • ๐Ÿ–– Use a high-performance auto-height for UITableViewCell and UITableViewHeaderFooterView. An internal height cache is also automatically managed.

License

BMLongPressDragCellCollectionView is released under the MIT license. See LICENSE for details.

Self-promo time! Here's some of my other programs. If you're interested, please check them out!

Convenient calendar app, supports holidays, breaks, etc Convenient payroll tax cut calculator
rl jsq