Skip to content

Instantly share code, notes, and snippets.

@RustemAqtau
Created February 15, 2022 10:56
Show Gist options
  • Save RustemAqtau/3906a0dbb5b81b6e1e9f2bd92e8bae1e to your computer and use it in GitHub Desktop.
Save RustemAqtau/3906a0dbb5b81b6e1e9f2bd92e8bae1e to your computer and use it in GitHub Desktop.
UIView button tap animation effect
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
DispatchQueue.main.async {
self.alpha = 1.0
UIView.animate(withDuration: 0.4, delay: 0.0, options: .curveLinear, animations: {
self.alpha = 0.5
}, completion: nil)
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
DispatchQueue.main.async {
self.alpha = 0.5
UIView.animate(withDuration: 0.4, delay: 0.0, options: .curveLinear, animations: {
self.alpha = 1.0
}, completion: nil)
}
}
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
DispatchQueue.main.async {
self.alpha = 0.5
UIView.animate(withDuration: 0.4, delay: 0.0, options: .curveLinear, animations: {
self.alpha = 1.0
}, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment