我想要在tableview中显示动态高度图像,图像来自url,所以我使用sdwebimage。 Sdwebimage在后台线程中设置图像。使用sdwebimage在tableview中动态图像高度
[self.imageView sd_setImageWithURL:[NSURL URLWithString: encodedurl1] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
}];
我正在更新此线程中图像视图的约束高度。
[self.imageView sd_setImageWithURL:[NSURL URLWithString: encodedurl1] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
CGFloat multiplier = (CGRectGetWidth(self.imageView.bounds)/image.size.width);
[self.imageViewHeightConstraint setConstant:multiplier * image.size.height];
}];
此代码对我来说是有益的,但我得到的图像大小在后台线程 所以,我需要时间来更新约束图像视图
我搜索和goggling最后2天的高度。 这种类型的问题得到了许多开发人员,但在堆栈溢出中没有回答任何问题。
尝试在下载图像时重新加载索引路径。并为imageview提供top,bottom,leading,trailing约束,并为imageview提供大于等于height height的约束。并将其添加到viewDidLoad中:tblViewDetail.estimatedRowHeight = 44.0; tblViewDetail.rowHeight = UITableViewAutomaticDimension; – KKRocks
尝试仅为tablesView传递estimatedRowHeight。 –