RMSwipeTableViewCell 0.6

RMSwipeTableViewCell 0.6

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

Rune Madsen维护。



  • 作者:
  • Rune Madsen

RMSwipeTableViewCell 是一个直接使用的 UITableViewCell 子类,支持类似于 Clear、Mailbox、Sparrow 等应用程序中看到的横滑手势。

RMSwipeTableViewCell 允许您轻松地创建子类以自定义单元格来满足您的需求。该类公开了有用的类方法和使用委托回调来处理 UITableViewController 中的操作的类方法。RMSwipeTableViewCell 与 iOS 5 及更高版本兼容!

RMSwipeTableViewCell 提供了开箱即用的功能,但具有许多属性,可以自定义用户与单元格的交互方式。

RMSwipeTableViewCellDemo Animation

高质量视频示例

RMSwipeTableViewCelliOS7Demo Animation

安装 RMSwipeTableViewCell

下面的示例和演示假设您正在为 iOS 6+ 编译。如果您正在支持较旧版本的 iOS,请使用适合初始化和 dequeuing 单元的适当方法。RMSwipeTableViewCell 与 iOS 5 及以上版本兼容。

RMSwipeTableViewCell 包含了两个演示。iOS 7 演示是尝试复制 Messages.app 中在 iOS 7 中看到的“删除模式”行为。该演示使用 iOS 6 SDK 构建。

手动

将仓库克隆到您的计算机或将其添加为子模块到您的项目中。

RMSwipeTableViewCell.hRMSwipeTableViewCell.m 添加到您的项目中。导入类头文件并在您的 UITableView 中注册单元格类。

#import "RMSwipeTableViewCell.h"
// add <RMSwipeTableViewCellDelegate> in your header file if you want to receive delegate callbacks on cell interactions

-(void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView registerClass:[RMSwipeTableViewCell class] forCellReuseIdentifier:CellIdentifier];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    RMSwipeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    cell.delegate = self; // optional
    return cell;
}

使用 RMSwipeTableViewCell

RMSwipeTableViewCell 可以直接使用,但您需要自定义 backView 等子视图以满足您的需求(请参阅 RMSwipeTableViewCell 的子类化)。

RMSwipeTableViewCellDemo 项目提供了一个使用自定义视图和操作子类化和自定义单元格的示例。

属性

RMSwipeTableViewCell 允许您自定义和控制动画和拖动手势。演示使用了所有默认状态。

UIView *backView;
RMSwipeTableViewCellRevealDirection revealDirection; // default is RMSwipeTableViewCellRevealDirectionBoth
RMSwipeTableViewCellAnimationType animationType; // default is RMSwipeTableViewCellAnimationTypeBounce
float animationDuration; // default is 0.2
BOOL shouldAnimateCellReset; // this can be overridden at any point (useful in the swipeTableViewCellWillResetState:fromLocation: delegate method). default is YES - note: it will reset to YES in prepareForReuse
BOOL panElasticity; // When panning/swiping the cell's location is set to exponentially decay. The rubber banding matches that of a UIScrollView/UITableView. default is YES
CGFloat panElasticityFactor; // This determines the exponential decay of the pan. By default it matches that of UIScrollView.
CGFloat panElasticityStartingPoint; // When using panElasticity this property allows you to control at which point elasticitykicks in. default is 0
UIColor *backViewbackgroundColor; // default is [UIColor colorWithWhite:0.92 alpha:1]

子类化 RMSwipeTableViewCell

子类化 RMSwipeTableViewCell 是在默认属性和任何委托回调之外自定义单元格的最佳方法。子类化允许您为 backView 创建子视图,根据需要扩展属性并覆盖类方法。

请参阅示例以了解子类化用法的示例。

RMSwipeTableViewCell 委托方法

RMSwipeTableViewCell 包含一些(可选)委托方法,这为子类设计和控制单元格功能提供了方便的扩展。委托方法设计简单,示例项目展示了几个使用方法的例子。

所有返回 CGPoint 位置的委托方法都考虑了 panOffset 值(panOffset 是 contentView 的实际位置与触摸位置平移值的差)。

// notifies the delegate when the user starts panning
-(void)swipeTableViewCellDidStartSwiping:(RMSwipeTableViewCell*)swipeTableViewCell;

// notifies the delegate when the panning location changes
-(void)swipeTableViewCell:(RMSwipeTableViewCell*)swipeTableViewCell didSwipeToPoint:(CGPoint)point velocity:(CGPoint)velocity;

// notifies the delegate when the user lifts their finger from the screen and cell will reset
-(void)swipeTableViewCellWillResetState:(RMSwipeTableViewCell*)swipeTableViewCell fromPoint:(CGPoint)point animation:(RMSwipeTableViewCellAnimationType)animation velocity:(CGPoint)velocity;

// notifies the delegate when the cell has reset itself back to its starting state. This is useful for doing further animation or updates on the cell after the reset animation has completed
-(void)swipeTableViewCellDidResetState:(RMSwipeTableViewCell*)swipeTableViewCell fromPoint:(CGPoint)point animation:(RMSwipeTableViewCellAnimationType)animation velocity:(CGPoint)velocity;

// Defaults to YES (the backView is recreated everytime the state is about to reset)
-(BOOL)swipeTableViewCellShouldCleanupBackView:(RMSwipeTableViewCell*)swipeTableViewCell;

致谢

由 Rune Madsen(@runmad 和 runmad.com)开发。

反馈

欢迎反馈。创建 Github 问题、拉取请求或通过 Twitter 与我联系。

如果您在项目中使用了它,希望看到并听到您的反馈。

许可证

《RMSwipeTableViewCell》遵循 MIT 许可协议。请参阅 LICENSE 文件以获取更多信息。

版本历史

0.6

  • 清理 init 逻辑
  • 添加新的委托方法 -(BOOL)swipeTableViewCellShouldCleanupBackView:(RMSwipeTableViewCell*)swipeTableViewCell;
  • 添加 panElasticityFactor
  • Xcode 5 文档
  • 处理 UIPanGestureRecognizer 的所有状态
  • 修复 UIViewAnimationOption 警告
  • 更新示例以支持 iOS 7 弹簧动画

0.5

  • 对 backView 和一些逻辑进行了一些改进
  • 添加了另一个示例,以展示对 iOS 7 行为和 UI 的调整

0.4

  • 添加 panElasticityStartingPoint 以允许更精细地控制弹性(如果启用)何时开始生效
  • 为 README 添加 .gif,以便在 Github 上更好地展示该类
  • 修复了在示例项目中发现的几个逻辑问题

0.3

  • 弃用了一系列委托方法,以改善返回的平移值
  • RMSwipeTableViewCellAnimationType 设置为与 UIViewAnimationOptions 匹配,以简化逻辑

0.2

0.1

  • 首次发布