I am thinking that the way to implement it would be using UIView.animate (...). But the part that got me stuck is about how to add gesture recogniser to detect touches. I tried to use UILongPressGestureRecognizer but that causes user to be unable to scroll through the cells. Any help here would be greatly appreciated.
Let me explain my question more clearly since some users here gave me irrelevant answers. Please refer to IOS 12 ShortCut App and see the cell shrinking effect as users scroll through the cells in the gallery tab
Below is my attempt to do the animations in didHighlight function. Although it works there is a slight delay between when the cell is tapped and when the cell start animating (around 0.1s to 0.3s), unlike the ShortCut app where the cell shrinks almost instantly and feels more natural
func collectionView(_ collectionView: UICollectionView, didHighlightItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
UIView.animate(withDuration: 0.1) {
cell?.transform = CGAffineTransform(scaleX: 0.95, y: 0.95)
}
}
func collectionView(_ collectionView: UICollectionView, didUnhighlightItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
UIView.animate(withDuration: 0.1) {
cell?.transform = CGAffineTransform(scaleX: 1, y: 1)
}
}