I have a collection view and each it its cell should have their own height based on it the image inside it
here I get data and resize the image based on that
public func configure(with data: Scraper) {
guard let imageURL = URL(string: data.imageURL) else { return }
KingfisherManager.shared.retrieveImage(with: imageURL) { [weak self] result in
guard let this = self else { return }
if let image = try? result.get().image {
this.setImageHeight(image: image)
this.imageView.image = image
}
}
}
private func setImageHeight(image: UIImage) {
let ratio = image.size.height/image.size.width
imageViewHeight.constant = imageViewWidth * ratio
}
and image constraint
imageViewHeight = NSLayoutConstraint(item: imageView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 0.0, constant: 0)
imageViewHeight.isActive = true
It works well for most of the cell, but some of the cell are not resized until doing more scroll then, they are all fine.
is there any better way to do that?
Thanks