gpt4 book ai didi

ios - 如何在 UIView 中显示所选 UICollectioNViewCell 的图像? ( swift 3)

转载 作者:搜寻专家 更新时间:2023-11-01 05:52:34 24 4
gpt4 key购买 nike

我是 iOS 开发的新手,所以如果这很明显,请多多包涵。

我在 View Controller 的下半部分有一个 UICollectionView;它当前显示我的照片库中的所有照片。同一个 View Controller 的上半部分有一个 UIView。

问:当我选择一个 UICollectionViewCell(即一张照片)时,如何在同一 View Controller 的 UIView 中显示该照片?

我想我必须以某种方式使用 didSelectItemAt 来保存所选图像的索引路径,以便在 UIView 中显示该图像。 (我已经包含了到目前为止 didSelectItemAt 的内容。)如何在选择不同的照片时刷新 UIView 的内容?

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let selectedVideo = collectionView.cellForItem(at: indexPath)
selectedVideo?.alpha = 0.5
}

func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
let deselectedVideo = collectionView.cellForItem(at: indexPath)
deselectedVideo?.alpha = 1.0
}

最佳答案

ImageView 放入您的 View 中,然后制作 imageview 的 IBOutlet。你得到 collectionview 的单元格,将 imageview 图像的 collectionviewcell 图像设置为顶部 imageView

你可以试试这个

 func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let selectedCell = collectionView.cellForItem(at: indexPath) as! MyCollectionViewCell
yourview.imageView.image = selectedCell.imageView.image
}

关于ios - 如何在 UIView 中显示所选 UICollectioNViewCell 的图像? ( swift 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43314645/

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