如何使细胞变大几秒钟?

时间:2019-05-29 09:50:42

标签: swift uicollectionview uicollectionviewcell

我有一个包含一些单元格的UICollection,我希望每个单元格之后的那个单元格都将被“选择”-将大小更改为更大并更改背景颜色,并像这样保持几秒钟,然后才能恢复正常。我在网络上找不到类似的东西。

1 个答案:

答案 0 :(得分:0)

您可以在CollectionView的委托上尝试以下代码:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    let scale: CGFloat = 1.2
    let animationDuration = 0.5
    let delay = 4.0
    UIView.animate(withDuration: animationDuration, animations: {
        collectionView.cellForItem(at: indexPath)?.transform = CGAffineTransform(scaleX: scale, y: scale)
    }) { (c) in
        UIView.animate(withDuration: animationDuration, delay: delay, options: .curveLinear, animations: {
            collectionView.cellForItem(at: indexPath)?.transform = .identity
        })
    }
}