嗨,我正在尝试将单元格高度设置为图像高度
我使用的是PinterestLayout,一切正常,但问题是在获取图像高度之前返回heightForPhotoAtIndexPath
func collectionView(_ collectionView: UICollectionView, heightForPhotoAtIndexPath indexPath: IndexPath) -> CGFloat {
// Get Object
let images = addArray[indexPath.row]["images"] as! [PFFile]
let image = images[0] as PFFile
image.getDataInBackground(block: { (data, error) in
if error == nil { if let imageData = data {
self.image2 = UIImage(data: imageData)!
self.height = self.image2.size.height
if self.height > 1000.0 {
self.height = self.height / 4.0
} else if self.height > 450 {
self.height = self.height / 3.0
}
print(self.height)
}}})
print(height)
return height
}
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 281.0 609.0 250.0 197.666666666667 281.0 281.0 281.0 281.0 281.0
答案 0 :(得分:0)
在我之前的项目中,我使用了Pinterest Layout,并且在下面进行了此方法。但是我不记得细节了。
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let itemSize = (collectionView.frame.width - (collectionView.contentInset.left + collectionView.contentInset.right + 10)) / 2
return CGSize(width: itemSize, height: itemSize)
}