Last active
March 7, 2022 21:14
-
-
Save HarshilShah/0509c4831b747340421e72d87aeb3372 to your computer and use it in GitHub Desktop.
UICollectionViewCell touch down animation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
really helpful, thanks!