2016-12-30 37 views
0

我試圖創建一個具有TabBarViewController以及4個選項卡(在故事板4個不同ViewControllers)的CollectionView細胞點擊擴大

在第一個選項卡是第一的ViewController演示應用新的觀點,我具有帶有ImageView和少量標籤的單元的collectionView 。

我想要做的是,當你點擊一個細胞,它擴展到整個屏幕,並認爲還處於從標籤欄, 第一標籤保持剛纔說的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() 
     } 


} 

回答

0

你必須重新加載集合視圖的代碼,同時也呼籲集合視圖的大小代表

+0

歡迎堆棧溢出!請在您的答案中添加一些代碼,以說明您的意思。 –

相關問題