如何使用可滑动的表格视图单元格实现与 iOS 邮件应用程序相同的功能?
How to achieve same functionality as iOS Mail app with swipeable tableview cell?
我正在尝试复制与股票 iOS 邮件应用程序相同类型的功能,当用户滑动 tableview 单元格时,如当前此处所示:
有 3 个选项:更多、标记和存档。当用户点击这 3 个中的任何一个时,背景颜色会发生变化以指示它处于突出显示状态。但是,图标和文本不会改变颜色。
我正在尝试达到同样的效果。
我正在按照本教程指南使用手势制作自定义可滑动的 tableview 单元格:
How To Make A Swipeable Table View Cell With Actions – Without Going Nuts With Scroll Views
目前我有这个设置:
在每个单元格中包含 3 个 UIViews
,其中每个 UIView
包含一个 UIImageView
和 UILabel
,分别代表 Dirty、Edit、Delete。
我正在向 3 UIViews
添加点击手势,如下所示:
let dirtyButtonView = cell.viewWithTag(7)
let editButtonView = cell.viewWithTag(8)
let deleteButtonView = cell.viewWithTag(9)
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(MyVC.buttonPressed))
tapRecognizer.numberOfTapsRequired = 1
dirtyButtonView?.addGestureRecognizer(tapRecognizer)
editButtonView?.addGestureRecognizer(tapRecognizer)
deleteButtonView?.addGestureRecognizer(tapRecognizer)
但是,当用户选择 3 个选项之一时,我无法实现邮件应用程序具有的高亮状态功能。
我不确定这是否是正确的实施方式,即是否有 UIView
并向其添加手势?
如何实现类似于 iOS 邮件应用滑动功能的功能?
谢谢
我会看一下 CEWendel 的 SWTableViewCell。它看起来正是您要找的东西。
我找到了我要找的东西,SwipeCellKit,作者是 jerkoch。该库执行与 iOS 邮件应用向左滑动时执行的完全相同的操作。无需处理不同的 UIViews
和 UIButtons
.
要使用,只需符合SwipeTableViewCellDelegate
,并在editActionsForRowAt
中使用,如下所示:
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
guard orientation == .right else { return nil }
let deleteAction = SwipeAction(style: .destructive, title: "Delete") { action, indexPath in
// handle action by updating model with deletion
}
// customize the action appearance
deleteAction.image = UIImage(named: "delete")
return [deleteAction]
}
确保将单元格的 class 更改为 SwipeTableViewCell
并像这样设置其委托:cell.delegate = self
.
可能会迟到回答这个问题,但如果其他人正在寻找 - 请考虑阅读这篇文章来回答问题:https://www.raywenderlich.com/62435/make-swipeable-table-view-cell-actions-without-going-nuts-scroll-views
我正在尝试复制与股票 iOS 邮件应用程序相同类型的功能,当用户滑动 tableview 单元格时,如当前此处所示:
有 3 个选项:更多、标记和存档。当用户点击这 3 个中的任何一个时,背景颜色会发生变化以指示它处于突出显示状态。但是,图标和文本不会改变颜色。
我正在尝试达到同样的效果。
我正在按照本教程指南使用手势制作自定义可滑动的 tableview 单元格:
How To Make A Swipeable Table View Cell With Actions – Without Going Nuts With Scroll Views
目前我有这个设置:
在每个单元格中包含 3 个 UIViews
,其中每个 UIView
包含一个 UIImageView
和 UILabel
,分别代表 Dirty、Edit、Delete。
我正在向 3 UIViews
添加点击手势,如下所示:
let dirtyButtonView = cell.viewWithTag(7)
let editButtonView = cell.viewWithTag(8)
let deleteButtonView = cell.viewWithTag(9)
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(MyVC.buttonPressed))
tapRecognizer.numberOfTapsRequired = 1
dirtyButtonView?.addGestureRecognizer(tapRecognizer)
editButtonView?.addGestureRecognizer(tapRecognizer)
deleteButtonView?.addGestureRecognizer(tapRecognizer)
但是,当用户选择 3 个选项之一时,我无法实现邮件应用程序具有的高亮状态功能。
我不确定这是否是正确的实施方式,即是否有 UIView
并向其添加手势?
如何实现类似于 iOS 邮件应用滑动功能的功能?
谢谢
我会看一下 CEWendel 的 SWTableViewCell。它看起来正是您要找的东西。
我找到了我要找的东西,SwipeCellKit,作者是 jerkoch。该库执行与 iOS 邮件应用向左滑动时执行的完全相同的操作。无需处理不同的 UIViews
和 UIButtons
.
要使用,只需符合SwipeTableViewCellDelegate
,并在editActionsForRowAt
中使用,如下所示:
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
guard orientation == .right else { return nil }
let deleteAction = SwipeAction(style: .destructive, title: "Delete") { action, indexPath in
// handle action by updating model with deletion
}
// customize the action appearance
deleteAction.image = UIImage(named: "delete")
return [deleteAction]
}
确保将单元格的 class 更改为 SwipeTableViewCell
并像这样设置其委托:cell.delegate = self
.
可能会迟到回答这个问题,但如果其他人正在寻找 - 请考虑阅读这篇文章来回答问题:https://www.raywenderlich.com/62435/make-swipeable-table-view-cell-actions-without-going-nuts-scroll-views