27
27
import UIKit
28
28
29
29
protocol BlurBackgroundPresentable : class {
30
- /// A reference to the ImageAnimationQueue object that handles image transition .
31
- var imageAnimationQueue : ImageAnimationQueue { get }
30
+ /// A reference to the background image view .
31
+ var backgroundImageView : UIImageView { get }
32
32
33
33
/// Sets up the background image view with a blur effect on top of it.
34
34
func setUpBlurBackground( )
@@ -43,7 +43,6 @@ extension BlurBackgroundPresentable where Self: UIViewController {
43
43
func setUpBlurBackground( ) {
44
44
view. backgroundColor = UIColor . tvBackgroundColor ( )
45
45
46
- let backgroundImageView = imageAnimationQueue. imageView
47
46
backgroundImageView. frame = view. bounds
48
47
backgroundImageView. contentMode = . scaleAspectFill
49
48
backgroundImageView. autoresizingMask = [ . flexibleWidth, . flexibleHeight]
@@ -58,9 +57,9 @@ extension BlurBackgroundPresentable where Self: UIViewController {
58
57
59
58
func animateBackgroundTransition( to image: UIImage ? ) {
60
59
// Throttle background image transition to avoid extensive changes in a short period of time.
61
- let selector = #selector( ImageAnimationQueue . animateBackgroundTransition ( to: ) )
62
- NSObject . cancelPreviousPerformRequests ( withTarget: imageAnimationQueue , selector : selector , object : nil )
63
- imageAnimationQueue . perform ( selector, with: image, afterDelay: 0.2 )
60
+ let selector = #selector( UIImageView . transition ( to: ) )
61
+ NSObject . cancelPreviousPerformRequests ( withTarget: backgroundImageView )
62
+ backgroundImageView . perform ( selector, with: image, afterDelay: 0.2 )
64
63
}
65
64
66
65
}
@@ -69,22 +68,16 @@ extension BlurBackgroundPresentable where Self: UIViewController {
69
68
////////////////////////////////////////////////////////////////////////////////
70
69
71
70
72
- class ImageAnimationQueue : NSObject {
71
+ extension UIImageView {
73
72
74
- fileprivate let imageView : UIImageView
75
-
76
- init ( imageView: UIImageView ) {
77
- self . imageView = imageView
78
- }
79
-
80
- @objc fileprivate func animateBackgroundTransition( to image: UIImage ? ) {
73
+ @objc fileprivate func transition( to image: UIImage ? ) {
81
74
Debug . print ( #function)
82
75
UIView . transition (
83
- with: imageView ,
76
+ with: self ,
84
77
duration: 0.5 ,
85
78
options: [ . beginFromCurrentState, . transitionCrossDissolve, . curveEaseIn] ,
86
79
animations: {
87
- self . imageView . image = image
80
+ self . image = image
88
81
} , completion: nil
89
82
)
90
83
}
0 commit comments