Skip to content

Instantly share code, notes, and snippets.

@jhurray
Created June 30, 2016 02:36
Show Gist options
  • Select an option

  • Save jhurray/7948000d8715789f641df627fb70b897 to your computer and use it in GitHub Desktop.

Select an option

Save jhurray/7948000d8715789f641df627fb70b897 to your computer and use it in GitHub Desktop.
Reload with fade
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