测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可 | MIT |
发布上次发布 | 2017年6月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 SenPng 主维护。
一个简单、可扩展的滑动 UITableViewCell
用于 Swift。包含 frontView
和 backView
,单元格可以左右滑动,您可以为它添加任何 UI 或操作。您甚至可以决定它们在单元格中显示的比例以及在滑动时保持的百分比。
XXSwipeableCell
非常简单易用。最常用的使用方法是创建自定义的 UITableViewCell
。只需继承 XXSwipeableCell
而不是 UITableViewCell
。
let cell = tableView.dequeueReusableCellWithIdentifier("XXSwipeableCell") as! XXSwipeableCell;
XXSwipeableCell
提供了以下公共属性及它们的默认值
/// The duration of the animation
public var animationDuration = 0.2;
/// The trigger ratio of left slide: 0<x<=1, if > 1 or <= 0 leftVisiblePercentage as a block sliding parameter
public var leftPercentage: CGFloat = -1.0;
/// The trigger ratio of right slide : 0<x<1, if > 1 or <= 0 rightVisiblePerCentage as a block sliding parameter
public var rightPercentage: CGFloat = 0.15;
/// The visible percentage on the left: 0 <= x <= 1
public var leftVisiblePercentage: CGFloat = 0.05;
/// The visible percentage on the right: 0 <= x <= 1
public var rightVisiblePercentage: CGFloat = 1.0;
/// Cover the entire screen, disappear when you click on the screen.
public class XXOverlayView: UIView
当您不调用方法:cell.close(true); 来恢复单元格的原始位置时,您必须手动通过调用方法:cell.overlayView?.removeFromSuperview(); 来移除 XXOverlayView。否则将出现一些问题。
然后,您可以根据项目中的需求调整这些属性。例如
cell.leftPercentage = 0.25
cell.leftVisiblePercentage = 0.3
cell.rightPercentage = 0.25
cell.rightVisiblePercentage = 0.5
此外,您还可以在 XXSwipeableCell
中的 frontView
或 backView
上添加任何 UI 和动作。我在这里为它们都添加了一个 UIButton
var button = UIButton(type: UIButtonType.System);
button.setTitle("Button", forState: UIControlState.Normal);
button.addTarget(self, action: #selector(ViewController.buttonAction(_:)), forControlEvents: UIControlEvents.TouchUpInside);
button.sizeToFit();
cell.backView.addSubview(button)
button.tag = 100;
button = UIButton(type: UIButtonType.System);
button.setTitle("Button", forState: UIControlState.Normal);
button.addTarget(self, action: #selector(ViewController.buttonAction(_:)), forControlEvents: UIControlEvents.TouchUpInside);
button.sizeToFit();
cell.frontView.addSubview(button);
button.tag = 101;
本项目中的演示是一个示例