gpt4 book ai didi

ios - 如何创建 pinterest 布局?

转载 作者:行者123 更新时间:2023-11-30 11:49:48 31 4
gpt4 key购买 nike

我正在尝试在我的应用程序中实现 Pinterest 布局,并且我尝试了 raywenderlich 中的教程。 。我的问题如何实现 UICollectionView cellForItemAt 和 heightForPhotoAtIndexPath

这是我的代码:

   func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "GaleryCollection", for: indexPath) as! GaleryCollectionViewCell
let imgGalery = self.galery![indexPath.row]
if imgGalery.photo != nil {
cell.imageGalery.af_setImage(withURL: URL(string: imgGalery.photo!)!)
}
return cell
}

最佳答案

我在我的项目中使用了相同的教程。我正在使用这个委托(delegate)函数。您需要导入 AVFoundation。如果您从数据库中提取图像,最好在数据库中设置图像的高度和宽度,以便轻松调用它们,如下所示。

func collectionView(collectionView: UICollectionView, heightForPhotoAt indexPath: IndexPath, with width: CGFloat) -> CGFloat {

let postHeight = posts[indexPath.item].postImageHeight
let postWidth = posts[indexPath.item].postImageWidth
let postSize = CGSize(width: postWidth, height: postHeight)
let boundingRect = CGRect(x: 0, y: 0, width: width, height: CGFloat(MAXFLOAT))
let rect = AVMakeRect(aspectRatio: postSize, insideRect: boundingRect)

return rect.size.height
}

我现在在附加对象时遇到问题。 :/

关于ios - 如何创建 pinterest 布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48459911/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com