YMSwipeTableViewCell 2.1.4

YMSwipeTableViewCell 2.1.4

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布最后发布2017年10月

Alda LuongPeter Willsey 维护。




  • 作者:
  • Alda Luong 和 Sumit Kumar

YMSwipeTableViewCell 是一个轻量级的库,它支持表视图单元格的滑动(如在大多数邮件应用中看到的)。它作为 UITableViewCell 类的类别实现,可以检测左右横向滑动。执行左右滑动时,将展示滑动视图。此库旨在灵活,以便在滑动期间暴露任何视图,并在滑动期间执行大量操作(例如,滑动视图动画或单元格在滑动完成时的瞬间或销毁)。

示例应用程序显示右侧视图为两个按钮,左侧视图为带勾选标记的单个按钮,其 alpha 值按滑动内容偏移的比例增加。

##功能

  • 用户可以完全控制在左右滑动期间暴露的视图。

  • 可配置单元格滑动效果

    • 揭露

- 跟随

* 在任何滑动时间执行动作的单元格滑动或单元格模式更改的回调 block。 * 可配置滑动到右侧或左侧视图的阈值。 * 配置多个单元格滑动的功能。 * 低开销和内存配置文件,原因如下: - 滑动视图直到开始滑动时才添加到视图中。 - 期间使用单元格快照而非实际单元格内容视图进行滑动动画。

##使用

  • 使用 UITableViewCell 类的类别实现一个新的单元格类。在这新的单元格类中,确保引入类别
#import "UITableViewCell+Swipe.h"
  • 创建所需的滑动视图。在本演示应用中,创建了用于右侧滑动视图的两个按钮视图 (YMTwoButtonSwipeView) 和用于左侧滑动视图的单个按钮视图 (YMOneButtonSwipeView)。

  • 初始化左右视图

YMTwoButtonSwipeView *rightView = [[YMTwoButtonSwipeView alloc] initWithFrame:CGRectMake(0, 0, kRightSwipeViewWidth, YMTableViewCellHeight)];
YMOneButtonSwipeView *leftView = [[YMOneButtonSwipeView alloc] init];

self.rightSwipeView = rightView;
self.leftSwipeView = leftView;
  • 通过调用 addLeftView 或 addRightView 设置左右视图。如果没有添加左侧视图,则禁用从左到右的滑动。如果没有添加右侧视图,则禁用从右到左的滑动。
[self addLeftView:self.leftSwipeView];
[self addRightView:self.rightSwipeView];
  • 通过设置滑动效果(默认值为 YATableSwipeEffectUnmask)来设置滑动效果
[cell setSwipeEffect:YATableSwipeEffectUnmask];
  • 设置 allowMultiple 标志以启用一次同时滑动的多个单元格(默认为 NO)
self.allowMultiple = YES;
  • 通过设置 swipeContainerViewBackgroundColor 改变默认的滑动容器视图背景颜色(默认颜色为灰色)
self.swipeContainerViewBackgroundColor = [UIColor grayColor];
  • 设置右和左滑动捕捉阈值值(默认值为 0,因此滑动开始时总是会执行右或左捕捉)
self.rightSwipeSnapThreshold = self.bounds.size.width * 0.3;
self.leftSwipeSnapThreshold = self.bounds.size.width * 0.1;
  • 设置 swipeBlock 通知子视图和/或视图控制器正在滑动
[self setSwipeBlock:^(UITableViewCell *cell, CGPoint translation){
    if (translation.x < 0) {
        [rightView didSwipeWithTranslation:translation];
    }
    else {
        [leftView didSwipeWithTranslation:translation];
    }
}];
  • 设置 modeChangedBlock 通知子视图和/或视图控制器滑动模式已更改
[self setModeChangedBlock:^(UITableViewCell *cell, YATableSwipeMode mode){
    [leftView didChangeMode:mode];
    [rightView didChangeMode:mode];
    
    if (weakSelf.delegate) {
        [weakSelf.delegate swipeableTableViewCell:weakSelf didCompleteSwipe:mode];
    }
}];
  • 可选设置 modeWillChangeBlock 通知子视图和/或视图控制器滑动模式将更改。

  • 根据您的观点,在ViewController的cellForRowAtIndexPath代理中,实例化表格视图单元格。

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    YMTableViewCell *cell = (YMTableViewCell*)[tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMTableViewCell class]) forIndexPath:indexPath];
    cell.delegate = self;
    if (indexPath.row % 2 == 0) {
        [cell setSwipeEffect:YATableSwipeEffectDefault];
        cell.textLabel.text = kYMSwipeTableViewCell0Title;
        cell.detailTextLabel.text = kYMSwipeTableViewCellDetailTitleSwipeLeftRight;
        cell.backgroundColor = [self unmaskingCellColor];
    } else {
        [cell setSwipeEffect:YATableSwipeEffectTrail];
        cell.textLabel.text = kYMSwipeTableViewCell1Title;
        cell.detailTextLabel.text = kYMSwipeTableViewCellDetailTitleSwipeLeftRight;
        cell.backgroundColor = [self trailingCellColor];
    }

    return cell;
}

安装

###选项1
克隆存储库并将源手动添加到项目中。

###选项3
CocoaPods

pod 'YMSwipeTableViewCell', '~> 2.1.1'

##贡献

使用GitHub问题来跟踪错误和功能请求。

##联系

Alda Luong

Sumit Kumar

##许可证

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