【问题标题】:CollectionView Cell clicked expand new viewCollectionView 单元格单击展开新视图
【发布时间】:2016-12-30 15:09:05
【问题描述】:

我正在尝试创建一个演示应用程序,它有一个 TabBarViewController 以及 4 个选项卡(情节提要上有 4 个不同的 ViewControllers)

在第一个 ViewController 的第一个选项卡上,我有一个 collectionView 具有 ImageView 和少量标签的单元格。

我想要做的是,当你点击一个单元格时,它会扩展到整个屏幕,并且视图仍然停留在标签栏的第一个标签中, 刚才 ViewController 中的视图已更改为一个新视图,它是所选单元格的展开视图,当您向下滚动时,集合视图继续,您可以单击另一个单元格并展开等等.. .虽然您可以随时按下返回,它会显示在视图中展开的最后一个单元格

我希望我对自己想要做的事情足够清楚。现在生病添加我已经拥有的代码

import UIKit

class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {


    var imagesArray = []

    var imageSizes = [CGSize]()

    var labelsArray = [""]

    var descArray = [""]



    @IBOutlet weak var collectionView: UICollectionView!


    override func viewDidLoad() {
        super.viewDidLoad()

        self.collectionView.delegate = self
        self.collectionView.dataSource = self

        for i in 0..<imagesArray.count {

            let currImg = imagesArray[i]
            let currHeight = currImg.size.height
            let currSize = CGSize(width: 150, height: currHeight + 125)
            imageSizes.append(currSize)
        }



       }





    public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return imagesArray.count
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! CollectionVCe

         cell.cellImg.image = imagesArray[indexPath.row]
        cell.descLabel.text = descArray[1]
        cell.itemLabel.text = labelsArray[0]


            cell.cellImg.contentMode = .scaleAspectFill
        cell.layer.cornerRadius = 9

      cell.backgroundColor = UIColor.red
        cell.cellImg.backgroundColor = UIColor.blue




        return cell
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return imageSizes[indexPath.row]
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        return UIEdgeInsetsMake(0, 25, 0, 25)
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 10

    }

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        if let cell = collectionView.cellForItem(at: indexPath) {
            cell.frame = collectionView.frame

        }
    }



override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
        }


}

【问题讨论】:

    标签: swift uicollectionviewcell uicollectionviewdelegate


    【解决方案1】:

    您已重新加载集合视图并调用集合视图的大小委托

    【讨论】:

    • 欢迎来到 Stack Overflow!请在您的答案中添加一些代码来说明您的意思。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    • 1970-01-01
    • 1970-01-01
    • 2015-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多