我想要在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。 –