Created
June 30, 2016 02:36
-
-
Save jhurray/7948000d8715789f641df627fb70b897 to your computer and use it in GitHub Desktop.
Reload with fade
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
| import UIKit | |
| protocol FadeReloadable { | |
| func reloadData() | |
| func reloadDataWithFade() | |
| } | |
| extension FadeReloadable where Self: UIView { | |
| private func setAlpha(alpha: CGFloat, completion: (Void -> Void)? = nil) { | |
| UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseInOut, animations: { () -> Void in | |
| self.alpha = alpha; | |
| }) { (finished: Bool) -> Void in | |
| completion?(); | |
| } | |
| } | |
| func reloadDataWithFade() { | |
| setAlpha(0.0) { | |
| self.reloadData() | |
| self.setAlpha(1.0) | |
| } | |
| } | |
| } | |
| extension UICollectionView : FadeReloadable {} | |
| extension UITableView : FadeReloadable {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment