Skip to content

Instantly share code, notes, and snippets.

@HarshilShah
Last active March 7, 2022 21:14
Show Gist options
  • Save HarshilShah/0509c4831b747340421e72d87aeb3372 to your computer and use it in GitHub Desktop.
Save HarshilShah/0509c4831b747340421e72d87aeb3372 to your computer and use it in GitHub Desktop.
UICollectionViewCell touch down animation
class CollectionViewCellAnimation: UICollectionViewCell {
override var isHighlighted: Bool {
didSet {
if isHighlighted {
handleTouchDown()
} else {
handleTouchUp()
}
}
}
private func handleTouchDown() {
UIView.animate(
withDuration: 0.05,
delay: 0,
options: [.beginFromCurrentState, .curveEaseInOut],
animations: { [weak self] in
self?.transform = CGAffineTransform(scaleX: 0.95, y: 0.95)
}, completion: nil)
}
private func handleTouchUp() {
UIView.animate(
withDuration: 0.1,
delay: 0,
options: [.beginFromCurrentState, .curveEaseInOut],
animations: { [weak self] in
self?.transform = .identity
}, completion: nil)
}
}
@cschep
Copy link

cschep commented Mar 7, 2022

really helpful, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment