I have a View which has two labels and a Table View inside it. I want label 1 to always stay above my Table View and label 2, to be below the Table View. The problem is that
Extending @nova answer to swift 4
tableViewSizeObservation = tableView.observe(\.contentSize) { [weak self] (tableView, _) in
tableView.layer.removeAllAnimations()
self?.tableViewHeightContraint.constant = tableView.contentSize.height
UIView.animate(withDuration: 0.5) {
self?.view.updateConstraints()
self?.view.layoutIfNeeded()
}
}
deinit {
tableViewSizeObservation?.invalidate()
}