ios - 滑动单元格时的 UITableViewCell 背景颜色动画
问题描述
我在滑动表格视图单元格时实现自定义动画时遇到问题。目标是在使用动画滑动单元格时更改单元格背景颜色。理想情况下,如果背景颜色根据 x 轴上的偏移量发生变化,那就完美了。或者如果不可能或很难做到,最好在滑动完成时完成动画。并且单元格的背景颜色应该与操作按钮的背景颜色相同。“滑动”意味着使按钮显示为默认删除操作的手势。
以下代码是当前代码。
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let action = UIContextualAction(style: .normal, title: "", handler: { (action,view,completionHandler ) in
completionHandler(true)
})
action.image = UIGraphicsImageRenderer(size: CGSize(width: 30, height: 30)).image { _ in
UIImage(named:"sell_btn")?.draw(in: CGRect(x: 0, y: 0, width: 30, height: 30))
}
action.backgroundColor = UIColor(hex: "#F4F4F4")
tableView.backgroundColor = .red
let confrigation = UISwipeActionsConfiguration(actions: [action])
return confrigation
}
此代码在调用此函数时更改背景颜色。
PS:我也尝试过 MGSwipeCell 和 SwipeCellKit,但它们并没有提供我想要的东西。
谢谢。
解决方案
推荐阅读
- css - 在包裹 div 的边框之间添加图标/img
- react-native - 如何解决世博会构建失败
- php - PHP数组按值和最小值-最大值分组
- sql - 如何使用三个表查找不匹配的记录?
- python - 邮递员正在工作,但我的 android 应用程序不工作 请帮帮我?这是我的代码和捕获
- spring - Pentaho j_spring_security_check 混合内容。HTTPS 到 HTTP
- c++ - 如何避免大量锁?
- java - 我可以使用 CompletableFuture 重复方法,直到值为 true
- forms - 表单字段被清空导致数据丢失
- mule - Mulesoft 为数组中的嵌套属性显示空值(即使它在我引用外部属性时显示这些值。)