0

我正在尝试创建一个具有 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()
        }


}
4

1 回答 1

1

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

于 2016-12-30T15:48:41.283 回答