Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 自定义UITableViewCell选择_Ios_Swift_Xcode_Uitableview_Uiviewanimation - Fatal编程技术网

Ios 自定义UITableViewCell选择

Ios 自定义UITableViewCell选择,ios,swift,xcode,uitableview,uiviewanimation,Ios,Swift,Xcode,Uitableview,Uiviewanimation,我发现了一个我无法解决的问题。目前,我有一个带有自定义单元格的tableView,在自定义单元格中,我编写了自己的setHighlighted和setSelected方法。我面临的问题是:当一个单元格高亮显示,然后选择一个“惊人”的动画正在发生 高亮显示:真动画:假 高亮显示:false动画:false 选定:真动画:假 选定:真实动画:真实 我错过了什么?我该如何解决这个问题 override func setHighlighted(_ highlighted: Bool, animate

我发现了一个我无法解决的问题。目前,我有一个带有自定义单元格的tableView,在自定义单元格中,我编写了自己的setHighlighted和setSelected方法。我面临的问题是:当一个单元格高亮显示,然后选择一个“惊人”的动画正在发生

  • 高亮显示:真动画:假
  • 高亮显示:false动画:false
  • 选定:真动画:假
  • 选定:真实动画:真实
我错过了什么?我该如何解决这个问题

override func setHighlighted(_ highlighted: Bool, animated: Bool) {
    super.setHighlighted(highlighted, animated: animated)

    if highlighted == true {
        UIView.animate(withDuration: 0.4, delay: 0.0, options: .curveEaseInOut, animations: {
            self.selectionView.backgroundColor = .red
        })
    } else if highlighted == false {
        UIView.animate(withDuration: 0.4, delay: 0.0, options: .curveEaseInOut, animations: {
            self.selectionView.backgroundColor = .clear
        })
    }
}

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    if selected == true && animated == true {
        UIView.animate(withDuration: 0.4, delay: 0, options: .curveEaseInOut, animations: {
            self.selectionView.backgroundColor = .red
        })

    } else {
        UIView.animate(withDuration: 0.4, delay: 0.0, options: .curveEaseInOut, animations: {
            self.selectionView.backgroundColor = .clear
        })
    }
}

@matt我指的是当前的用例导致了一个bug。如果你愿意,我会把它删掉prefer@matt对不起,我不明白你在说什么我的代码中的错误是什么?你能详细说明一下吗?