Вам нужно позвонить layoutIfNeeded()
на view
в UIView.animate(withDuration:animations:)
animations closure
после установки значения imgViewHeight.constant
.
extension DetailViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if (self.lastContentOffset > scrollView.contentOffset.y) {
UIView.animate(withDuration: 0.2) {[weak self] in
self?.imgViewHeight.constant = 20 //This is just an example
self?.view.layoutIfNeeded() //Here..........
}
}
else if (self.lastContentOffset < scrollView.contentOffset.y) {
UIView.animate(withDuration: 0.2) {[weak self] in
self?.imgViewHeight.constant = 0 //This is just an example
self?.view.layoutIfNeeded() //Here..........
}
}
//Rest of the code...
}
}
В приведенном выше коде я использовал примеры значений height constraint (20 and 0)
. Вместо этого добавьте свою собственную логику height
.