WDragableMenu 1.0.0

WDragableMenu 1.0.0

KWei19 维护。



  • KWei

WDragableMenu

WDragableMenu 允许通过拖放操作重新排列项的位置。WDragableMenu 还为用户提供两个部分,用户可以将项添加到或从第一个部分中删除。

预览

安装

克隆仓库,并在 Example 目录中运行 pod install

介绍

WDragableMenu 的初始化

首先需要初始化 WDragableMenu 类并设置代理。

- (WDragableMenu *)menuVC {
if (!_menuVC)
{
    _menuVC = [[WDragableMenu alloc] init];
    [_menuVC setTypeMenu:ReoderAndEditable];
    [_menuVC setIsCellAnimationEnabled:NO];
    [_menuVC setDragableMenuDelegate:self];
}
return _menuVC;
}
private lazy var menuVC: WDragableMenu = {
    let menuVC = WDragableMenu()
    menuVC.typeMenu = OnlyReorder
    menuVC.dragableMenuDelegate = self
    return menuVC
}()

协议 WDragableMenuDelegate

@required

  1. - (NSInteger)totalItemsInPrimarySection - 获取显示在主节区的项目总数

  2. - (nonnull NSString *)getTitleForCellInPrimarySection:(NSInteger)selectedItem - 获取在第一部分的菜单单元格将显示的文本

  3. - (void)userUpdatedMenuSequence - 通知用户菜单序列已发生变化

  4. - (void)tapOnMenuItem:(NSInteger)selectedIndex - 当点击菜单项时的代理操作

  5. - (void)updateSequenceOfArrayWithOriginalIndex:(NSInteger)originalIndex withDestinationIndex:(NSInteger) destinationIndex - 更新第一部分数组顺序的代理,重新排列菜单操作被触发时使用

@optional - 需要 WHEN WDragableMenuType 是 ReoderAndEditable

  1. - (NSInteger)totalItemsInSecondarySection - 获取显示在第二部分的项目总数

  2. - (nonnull NSString *)getTitleForCellInSecondarySection:(NSInteger)selectedItem - 获取在第二部分的菜单单元格将显示的文本

  3. - (void)addItemWithSelectedIndex:(NSInteger)selectedIndex - 从第二部分将菜单项添加到第一部分

  4. - (void)removeItemWithSelectedIndex:(NSInteger)selectedIndex - 从第一部分移除菜单项

WDragableMenu的属性

WDragableMenuType

@property (nonatomic, assign) WDragableMenuType typeMenu; 用于决定collectionMenu如何显示的枚举值

OnlyReoder - 只有一个菜单部分可以显示,只能重新排序 ReoderAndEditable - 有两个菜单部分可以显示,可以重新排序菜单序列,也可以添加/移除菜单序列

如果没有为其设置任何值,默认值为 "OnlyReoder"

numItemsFreeze

@property (nonatomic) NSInteger numItemsFreeze; numItemsFreeze 提供了一个控制功能,应用程序可以决定第一部分有多少项目将被冻结。默认值是 前两个项目 例子

self.numItemsFreeze = 3;

numItemsinRow

@property (nonatomic) NSInteger numItemsinRow; 提供 numItemsinRow 控制在一行中显示多少个项目。 默认值 4 示例

self.numItemsinRow = 3;

isCellAnimationEnabled

@property (nonatomic, assign) BOOL isCellAnimationEnabled; isCellAnimationEnabled 控制menuitem的动画。 默认值 YES 示例

self.isCellAnimationEnabled = NO;

参考

https://mobikul.com/ios-longpress-drag-and-drop-using-uicollectionview-with-animation/

许可

WDragableMenu 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。