I need to expand or collapse a table view cell and its contents.
For that I'm using NSLayoutConstraints. Though it gets the work done, I'm facing some pesky layout issues with other views in the cell.
Here is a video.
And here is my code:
ViewController:
extension ViewController: TableViewCellDelegate {
func tableView(shouldExpand cell: TableViewCell) {
tableView.performBatchUpdates({
cell.expand()
})
}
func tableView(shouldCollapse cell: TableViewCell) {
tableView.performBatchUpdates({
cell.collapse()
})
}
}
TableViewCell:
func expand() {
UIView.animate(withDuration: 0.57) {
self.viewHeight.constant = 320
self.view.alpha = 1
self.layoutIfNeeded()
}
}
func collapse() {
UIView.animate(withDuration: 0.57) {
self.viewHeight.constant = 0
self.view.alpha = 0
self.layoutIfNeeded()
}
}
How to stop the upper view stop resizing?