Skip to content

Commit 5379be5

Browse files
committed
optimize gif animator
1 parent a3ddabe commit 5379be5

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

Infinity/controls/gif/GIFInfinityAnimator.swift

+2-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ import UIKit
1010

1111
open class GIFInfiniteAnimator: UIView, CustomInfiniteScrollAnimator {
1212

13-
open var animatedImages:[UIImage]? {
14-
didSet {
15-
imageView.animationImages = animatedImages
16-
}
17-
}
13+
open var animatedImages = [UIImage]()
1814

1915
var imageView: UIImageView = UIImageView()
2016

@@ -37,6 +33,7 @@ open class GIFInfiniteAnimator: UIView, CustomInfiniteScrollAnimator {
3733
}
3834
}
3935
func startAnimating() {
36+
imageView.animationImages = animatedImages
4037
imageView.isHidden = false
4138
imageView.startAnimating()
4239
}

Infinity/controls/gif/GIFRefreshAnimator.swift

+5-8
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ import UIKit
1010

1111
open class GIFRefreshAnimator: UIView, CustomPullToRefreshAnimator {
1212

13-
open var refreshImages:[UIImage]?
14-
open var animatedImages:[UIImage]? {
15-
didSet {
16-
imageView.animationImages = animatedImages
17-
}
18-
}
13+
open var refreshImages = [UIImage]()
14+
open var animatedImages = [UIImage]()
1915

2016
fileprivate var imageView:UIImageView = UIImageView()
2117

@@ -41,17 +37,18 @@ open class GIFRefreshAnimator: UIView, CustomPullToRefreshAnimator {
4137
}
4238
}
4339
func updateForProgress(_ progress: CGFloat) {
44-
if let refreshImages = refreshImages {
40+
if refreshImages.count > 0 {
4541
let currentIndex = min(Int(progress * CGFloat(refreshImages.count)), refreshImages.count - 1)
4642
imageView.image = refreshImages[currentIndex]
4743
}
4844
}
4945
func startAnimating() {
46+
imageView.animationImages = animatedImages
5047
imageView.startAnimating()
5148
}
5249
func stopAnimating() {
5350
imageView.stopAnimating()
54-
imageView.image = refreshImages?.first
51+
imageView.image = refreshImages.first
5552
}
5653
/*
5754
// Only override drawRect: if you perform custom drawing.

0 commit comments

Comments
 (0)