У меня есть UIImageview внутри UITableViewCell, высота которого должна меняться в зависимости от масштаба изображения, поэтому я сделал
override func viewDidLoad() {
...
tableView.estimatedRowHeight = 500.0 //arbitrary value
tableView.rowHeight = UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
//change height of UIImageView
let image_width = homeViewCell.mainImageView.frame.size.width
let image_height = image_width * CGFloat(viewModel.imageScale)
homeViewCell.mainImageView.frame.size.height = image_width * CGFloat(viewModel.imageScale)
//load image
_ = homeViewCell.mainImageView.af_setImage(withURL: URL(string: serverURL + viewModel.mainImage)!, placeholderImage: UIImage(named : "home_placeholder") ...
}
В раскадровке я установил ограничение высоты просмотра изображения в виде фиксированного числа, а в режиме содержимого - «Масштаб для заполнения»
Это не изменение размера UIImageView в зависимости от масштаба изображения.