Skip to content

Instantly share code, notes, and snippets.

@ytyubox
Created April 5, 2021 10:51
Show Gist options
  • Save ytyubox/339fc0514e2ac4817b7bc3389943005d to your computer and use it in GitHub Desktop.
Save ytyubox/339fc0514e2ac4817b7bc3389943005d to your computer and use it in GitHub Desktop.
Tap To Squeeze On Cell and Control
/* Also working with UIControl, UITableViewCell */
class Cell: UICollectionViewCell {
override var isHighlighted: Bool {
didSet {
let duration = isHighlighted
? 0.45
: 0.4
let transform = isHighlighted
? CGAffineTransform(scaleX: 0.96, y: 0.96)
: CGAffineTransform.identity
let bgColor = isHighlighted
? UIColor(white: 1.0, alpha: 0.2)
: UIColor(white: 1.0, alpha: 0.1)
let animations = {
self.transform = transform
self.bgView.backgroundColor = bgColor
}
UIView.animate(withDuration: duration,
delay: 0,
usingSpringWithDamping: 1.0,
initialSpringVelocity: 0.0,
options: [.allowUserInteraction, .beginFromCurrentState],
animations: animations,
completion: nil)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment