I need an animation when a collection view cell is tapped. I wrote an override function for it. But UICollectionView didSelectItemAt is not working when I override touchesBegan on the custom cell.
ViewController
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
self.answersCollectionView.selectItem(at: indexPath, animated: true, scrollPosition: .centeredHorizontally)
self.selectedIndex = indexPath.item
}
CustomCellClass
public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
UIView.animate(withDuration: 0.5) {
self.transform = CGAffineTransform(scaleX: 0.9, y: 0.9)
}
}
public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
UIView.animate(withDuration: 0.1) {
self.transform = CGAffineTransform(scaleX: 1, y: 1)
}
}
public override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
UIView.animate(withDuration: 0.1) {
self.transform = CGAffineTransform(scaleX: 1, y: 1)
}
}
I want to animate the selection.
touchesBeganadd:super.touchesBegan(touches, with: event)answersCollectionViewa different collection view? If not, you are calling.selectItem(at:...insidedidSelectItemAt, which doesn't make any sense.