My problem is really simple. I would like to animate a cell within a collectionView. Indeed, I would like to show a grey background behind the cell and scale down the image
Swift : 4 You need to implement custom UICollectionViewCell, change the contentView OR imageView transform when the cell is selected
override var isSelected: Bool {
didSet{
UIView.animate(withDuration: 1.0, animations:
{
self.contentView.transform = self.isSelected ? CGAffineTransform(scaleX: 0.95, y: 0.95) : CGAffineTransform.identity
self.contentView.backgroundColor = UIColor(red: 0.95, green: 0.95, blue: 0.95, alpha: 1)
}) { (true) in
UIView.animate(withDuration: 0.5, animations:
{
self.contentView.transform = self.isSelected ? CGAffineTransform(scaleX: 1.0, y: 1.0) : CGAffineTransform.identity
self.contentView.backgroundColor = UIColor.clear
})
}
}
}