【发布时间】:2021-09-11 15:36:14
【问题描述】:
我在滚动后为自定义表格单元格设置动画时遇到问题。我需要使用滚动动画滚动到特定索引,然后通过更改单元格背景突出显示单元格。
我使用滚动
self.tableView.scrollToRow(at: index_path, at: position, animated: true)
在 willDisplayCell 回调中,我将动画添加到我使用 CAAnimation 滚动到的单元格中。
let animation = CABasicAnimation(keyPath: "backgroundColor")
animation.fromValue = UIColor.white.cgColor
animation.toValue = UIColor.blue.withAlphaComponent(0.4).cgColor
animation.duration = 1
animation.autoreverses = true
animation.isRemovedOnCompletion = true
cell.contentView.layer.add(animation, forKey: "any key")
单元格背景颜色更改动画不起作用。我认为表格单元格滚动动画会覆盖添加的动画。有什么解决方法吗?(注意:我也需要滚动动画)
【问题讨论】:
-
尝试
UIView.animate而不是CABasicAnimation.. -
@NayanDave . 好的。我会尝试并回复您。
-
@NayanDave,不,它没有帮助
-
试试
DispatchQueue.main.async{ TableView_Scroll_Code } -
尝试在 UITableView 的 prepareForReuse 方法中添加动画。该方法用于@Documentation“重置与内容无关的单元格属性,例如alpha、编辑、选择状态。”
标签: uitableview swift5 caanimation