Last active
July 25, 2018 11:49
-
-
Save wata/155bb722b8719a0e163029cee520be65 to your computer and use it in GitHub Desktop.
Animations of FadeIn / FadeOut
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
| // Modified from: https://qiita.com/mono0926/items/c53b2e46e51a0b0bbf06 | |
| enum FadeType: TimeInterval { | |
| case normal = 0.2 | |
| case slow = 1.0 | |
| } | |
| extension UIView { | |
| func fadeIn(_ type: FadeType = .normal, completion: (() -> Void)? = nil) { | |
| self.alpha = 0 | |
| self.isHidden = false | |
| UIView.animate(withDuration: type.rawValue, animations: { | |
| self.alpha = 1 | |
| }, completion: { _ in | |
| completion?() | |
| }) | |
| } | |
| func fadeOut(type: FadeType = .normal, completion: (() -> Void)? = nil) { | |
| UIView.animate(withDuration: type.rawValue, animations: { | |
| self.alpha = 0 | |
| }, completion: { [weak self] _ in | |
| self?.isHidden = true | |
| self?.alpha = 1 | |
| completion?() | |
| }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment