あなたがセルに触れたときにアニメーションを開始したい場合は、 didHighlightItemAt
を実装できます。おそらくdidUnhighlightItemAt
でそれを逆にする:
override func collectionView(_ collectionView: UICollectionView, didHighlightItemAt indexPath: IndexPath) {
UIView.animate(withDuration: 0.5) {
if let cell = collectionView.cellForItem(at: indexPath) as? CustomCell {
cell.imageView.transform = .init(scaleX: 0.95, y: 0.95)
cell.contentView.backgroundColor = UIColor(red: 0.95, green: 0.95, blue: 0.95, alpha: 1)
}
}
}
override func collectionView(_ collectionView: UICollectionView, didUnhighlightItemAt indexPath: IndexPath) {
UIView.animate(withDuration: 0.5) {
if let cell = collectionView.cellForItem(at: indexPath) as? CustomCell {
cell.imageView.transform = .identity
cell.contentView.backgroundColor = .clear
}
}
}
それ収量を:
![demo](https://i.stack.imgur.com/xoRQZ.gif)
出典
2017-08-13 19:23:33
Rob
私はタッチダウンアクションを出せ、と – KevinB