Created
February 15, 2022 10:56
-
-
Save RustemAqtau/3906a0dbb5b81b6e1e9f2bd92e8bae1e to your computer and use it in GitHub Desktop.
UIView button tap animation effect
This file contains hidden or 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
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