У меня была проблема с созданием разворачивающихся ячеек.Я использую UIStackView.Проблема в том, что, когда ячейка свернута, нижний вид переходит поверх и получается уродливая анимация.
вот мои методы
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("tap")
self.tableView.beginUpdates()
let cell = tableView.cellForRow(at: indexPath) as! TableViewCell
cell.animate(duration: 0, c: {
cell.stufView.layoutIfNeeded()
})
self.tableView.endUpdates()
}
и метод ячейки animate
func animate(duration:Double, c: @escaping () -> Void) {
UIView.animateKeyframes(withDuration: duration, delay: 0, options: .calculationModePaced, animations: {
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: duration, animations: {
self.stufView.isHidden = !self.stufView.isHidden
if self.stufView.alpha == 1 {
self.stufView.alpha = 0.5
} else {
self.stufView.alpha = 1
}
})
}, completion: { (finished: Bool) in
print("animation complete")
c()
})
}
моя раскадровка