Вы должны отдельно написать два расширения для каждого UITableViewCell и UICollectionViewCell
Расширение UITableViewCell
extension UITableViewCell {
func showAnimation() {
var transform = CGAffineTransform.identity
transform = transform.scaledBy(x: 0.96, y: 0.96)
UIView.animate(withDuration: 3.3, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: [], animations: {
self.transform = transform
}, completion: nil)
}
}
Теперь вы можете вызвать showAnimation () когда пользователь нажимает
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.cellForRow(at: indexPath)?.showAnimation()
}
То же самое можно сделать и для UIcollectionViewCell *