如何解决UITableView:拖动单元格时如何更改重叠单元格的背景?
我附上了一张图片。
这是 iPhone 的默认提醒应用。 像这样,当拖动单元格重叠时,我想制作灰色背景。
这是我尝试过的:;但它在模拟器中看起来很丑。
var beforetouch: IndexPath?
func tableView(_ tableView: UITableView,targetIndexPathForMoveFromrowAt sourceIndexPath: IndexPath,toProposedindexPath proposedDestinationIndexPath: IndexPath) -> IndexPath {
if let cell = tableView.cellForRow(at: proposedDestinationIndexPath) {
if (self.beforetouch != sourceIndexPath)
&& (sourceIndexPath != proposedDestinationIndexPath) {
if self.beforetouch == nil {
cell.setSelected(true,animated: false)
} else {
cell.setSelected(true,animated: false)
tableView.cellForRow(at: beforetouch!)?.setSelected(false,animated: false)
}
}
self.beforetouch = proposedDestinationIndexPath
}
return proposedDestinationIndexPath
}
func tableView(_:,targetIndexPathForMoveFromrowAt:,toProposedindexPath:) -> IndexPath
好像每次拖动时都会执行,可以通过参数的IndexPath来追踪单元格。
另外,我认为会出现性能问题,因为'cell.setSelected()' 用于在拖动时连续调用的tableView 函数中。我也遇到了必须把前一个单元格的indexPath存储在类的storage属性中的问题,所以我正在寻找另一种方式。
有人可以帮助我如何实现它吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。