- 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+
)
pod 'BMLongPressDragCellCollectionView'
pod install
#import "BMLongPressDragCellCollectionView.h"
- Download the project:
git clone https://github.com/liangdahong/BMLongPressDragCellCollectionView.git
- Drag and drop all the contents of the
BMLongPressDragCellCollectionView
folder to your project
BMLongPressDragCellCollectionView
is a subclass ofUICollectionView
, so usage is the exact same asUICollectionView
. Just replaceUICollectionView
withBMLongPressDragCellCollectionView
in your Xib or Storyboard.- Replace your
UICollectionViewDataSource
withBMLongPressDragCellCollectionViewDataSource
- Replace your
UICollectionViewDelegateFlowLayout
withBMLongPressDragCellCollectionViewDelegate
- 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 internalcell
data source's sort processing.
- (NSArray< NSArray<id> *> *)dataSourceWithDragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView;
Implementation:
- (NSArray<NSArray<id> *> *)dataSourceWithDragCellCollectionView:(__kindof BMLongPressDragCellCollectionView *)dragCellCollectionView {
return self.dataSourceArray;
}
- Implement the proxy method, which is called when a
cell
is swapped with anothercell
. 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];
}
In a Xib or Storyboard, you only need the above 3 steps to make your UICollectionView
support drag and drop rearrangement perfectly.
Programmatically, you only need the above 3 steps to make your UICollectionView
support drag and drop rearrangement perfectly.
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
)
- A pure Swift rewrite is planned for August 5, 2020...
- The core implementation is based off XWDragCellCollectionView. Special thanks!
- ๐ Use a high-performance auto-height for
UITableViewCell
andUITableViewHeaderFooterView
. An internal height cache is also automatically managed.
BMLongPressDragCellCollectionView is released under the MIT license. See LICENSE for details.
Convenient calendar app, supports holidays, breaks, etc | Convenient payroll tax cut calculator |
---|---|
![]() |
![]() |