Animate cell when pressed using Swift 3

后端 未结 6 2156
感情败类
感情败类 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:00

    If you need implement this functionality only for the specific cell, just add this code to you cell implementation:

    override var isHighlighted: Bool {
      didSet {
        UIView.animate(withDuration: 0.5) {
          let scale: CGFloat = 0.9
          self.transform = self.isHighlighted ? CGAffineTransform(scaleX: scale, y: scale) : .identity
        }
      }
    }
    

    It is the same answer that suggested [pgdev][1] but for isHighlighted

提交回复
热议问题