测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可 | MIT |
发布最后发布 | 2017年10月 |
由 Alda Luong 和 Peter Willsey 维护。
YMSwipeTableViewCell 是一个轻量级的库,它支持表视图单元格的滑动(如在大多数邮件应用中看到的)。它作为 UITableViewCell 类的类别实现,可以检测左右横向滑动。执行左右滑动时,将展示滑动视图。此库旨在灵活,以便在滑动期间暴露任何视图,并在滑动期间执行大量操作(例如,滑动视图动画或单元格在滑动完成时的瞬间或销毁)。
示例应用程序显示右侧视图为两个按钮,左侧视图为带勾选标记的单个按钮,其 alpha 值按滑动内容偏移的比例增加。
##功能
用户可以完全控制在左右滑动期间暴露的视图。
可配置单元格滑动效果
##使用
#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;
[self addLeftView:self.leftSwipeView];
[self addRightView:self.rightSwipeView];
[cell setSwipeEffect:YATableSwipeEffectUnmask];
self.allowMultiple = YES;
self.swipeContainerViewBackgroundColor = [UIColor grayColor];
self.rightSwipeSnapThreshold = self.bounds.size.width * 0.3;
self.leftSwipeSnapThreshold = self.bounds.size.width * 0.1;
[self setSwipeBlock:^(UITableViewCell *cell, CGPoint translation){
if (translation.x < 0) {
[rightView didSwipeWithTranslation:translation];
}
else {
[leftView didSwipeWithTranslation:translation];
}
}];
[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文件。