Animate cell when pressed using Swift 3

后端 未结 6 2167
感情败类
感情败类 2020-12-23 10:30

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

6条回答
  •  滥情空心
    2020-12-23 11:13

    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
                            })
                        } 
                     }
                 }
    

提交回复
热议问题