self.tableView.addObserver(self, forKeyPath: "contentSize", options: [.new, .old, .prior], context: nil)
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "contentSize" {
if let oldValue = change?[NSKeyValueChangeKey.oldKey] as? CGSize, let newValue = change?[NSKeyValueChangeKey.newKey] as? CGSize {
if oldValue.height != newValue.height {
tableView.snp.updateConstraints { make in
make.height.equalTo(newValue.height)
}
}
}
}
}
网友评论