我有一个包含一些单元格的 UICollection,我希望每个单元格都将被“选中”- 将大小更改为更大并更改背景颜色,并在恢复正常之前保持这种状态几秒钟。我在网上找不到类似的东西。
最佳答案
您可以在 CollectionView 的委托(delegate)上尝试此代码:
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
})
}
}
关于swift - 如何让细胞变大几秒钟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56357732/