ios - 为什么在覆盖自定义单元格的 setSelected 方法后,表格视图单元格每次在滚动时出现时都会被选中?
问题描述
我尝试为表格视图单元格选择制作自定义动画,因此我使用以下代码覆盖了自定义单元格的 setSelected 方法:
override func setSelected(_ selected: Bool, animated: Bool) {
if self.frame.size.height == 132{
self.backgroundViewTop.constant = 40
UIViewPropertyAnimator.runningPropertyAnimator(withDuration: 0.08, delay: 0, options: [.curveEaseIn], animations: {
self.backView.backgroundColor = UIColor(red: 0.891, green: 0.9, blue: 0.9, alpha: 1)
}, completion: { finished in
UIViewPropertyAnimator.runningPropertyAnimator(withDuration: 0.2, delay: 0, options: [.curveEaseIn], animations: {
self.backView.backgroundColor = UIColor.white
}, completion: nil )
})
}else{
self.backgroundViewTop.constant = 0
UIViewPropertyAnimator.runningPropertyAnimator(withDuration: 0.08, delay: 0, options: [.curveEaseIn], animations: {
self.backView.backgroundColor = UIColor(red: 0.891, green: 0.9, blue: 0.9, alpha: 1)
}, completion: { finished in
UIViewPropertyAnimator.runningPropertyAnimator(withDuration: 0.2, delay: 0, options: [.curveEaseIn], animations: {
self.backView.backgroundColor = UIColor.white
}, completion: nil )
})
}
}
现在,当我滚动屏幕上出现新的单元格时,就会出现这个动画。为什么要调用此方法,并以正确的方式覆盖它以在选择时实现自定义动画?
解决方案
推荐阅读
- google-bigquery - 使用私有 IP 将 BigQuery 连接到 CloudSQL
- usb - 使用wireshark进行USB嗅探描述
- anaconda - Python 库文件夹后跟点
- rust - 为什么有时 my_arc_mutex.clone() 在完成使用之前会被释放?
- html - 在 jQuery 中,按键不会在第三次按下时触发功能
- javascript - 为什么我的简单 JSON 检索代码不适用于 OMDb?
- python - Monkey-patching `__reduce__` 自定义单个对象的酸洗
- javascript - 无法在 axios 上添加授权标头
- go - 二叉搜索树的删除函数不删除叶子节点
- python - 如何匹配此模式和字符串中的最后一个空格?