更改所选UICollectionView单元的大小

时间:2017-01-15 14:00:08

标签: swift uicollectionview swift3 uicollectionviewcell uicollectionviewlayout

我有一个简单的UICollectionViewController,它返回X个单元格。我想拥有它,所以当选择一个单元格时,特定的选定单元格会改变它的大小,并且随着所有其他单元格保持不变而变得更大。我该如何实现这一目标?这是我的代码:

class HomeController: UICollectionViewController, UICollectionViewDelegateFlowLayout {

    let cellId = "cellId"

    override func viewDidLoad() {
        super.viewDidLoad()
        collectionView?.backgroundColor = UIColor(white: 0.90, alpha: 1.0)

        collectionView?.register(PostCell.self, forCellWithReuseIdentifier: cellId)
        collectionView?.showsVerticalScrollIndicator = false
        collectionView?.alwaysBounceVertical = true
    }

    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 4
    }

    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! PostCell
        return cell
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let height = (view.frame.width) * 9 / 16
        return CGSize(width: view.frame.width, height: height + 50 + 50)
    }
}

1 个答案:

答案 0 :(得分:10)

您可以查看是否已选择/* Attempting to display any redundant pipe Info here if it exist */ redundantPipeInfo(); 中的@types/bluebird-global。如果是,则返回不同的高度,否则返回标准高度。

indexPath