Skip to content

Commit fb3c7ca

Browse files
committed
Use the background image view as the receiver to perform methods after delay
1 parent 389994d commit fb3c7ca

File tree

4 files changed

+12
-19
lines changed

4 files changed

+12
-19
lines changed

iCookTV/Controllers/CategoriesViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class CategoriesViewController: UIViewController,
5656

5757
// MARK: - BlurBackgroundPresentable
5858

59-
let imageAnimationQueue = ImageAnimationQueue(imageView: UIImageView())
59+
let backgroundImageView = UIImageView()
6060

6161
// MARK: - Initialization
6262

iCookTV/Controllers/HistoryViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class HistoryViewController: UIViewController,
3939

4040
// MARK: - BlurBackgroundPresentable
4141

42-
let imageAnimationQueue = ImageAnimationQueue(imageView: UIImageView())
42+
let backgroundImageView = UIImageView()
4343

4444
// MARK: - DropdownMenuPresentable
4545

iCookTV/Controllers/VideosViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class VideosViewController: UIViewController,
5656

5757
// MARK: - BlurBackgroundPresentable
5858

59-
let imageAnimationQueue = ImageAnimationQueue(imageView: UIImageView())
59+
let backgroundImageView = UIImageView()
6060

6161
// MARK: - DataFetching
6262

iCookTV/Protocols/BlurBackgroundPresentable.swift

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import UIKit
2828

2929
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 }
3232

3333
/// Sets up the background image view with a blur effect on top of it.
3434
func setUpBlurBackground()
@@ -43,7 +43,6 @@ extension BlurBackgroundPresentable where Self: UIViewController {
4343
func setUpBlurBackground() {
4444
view.backgroundColor = UIColor.tvBackgroundColor()
4545

46-
let backgroundImageView = imageAnimationQueue.imageView
4746
backgroundImageView.frame = view.bounds
4847
backgroundImageView.contentMode = .scaleAspectFill
4948
backgroundImageView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
@@ -58,9 +57,9 @@ extension BlurBackgroundPresentable where Self: UIViewController {
5857

5958
func animateBackgroundTransition(to image: UIImage?) {
6059
// 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)
6463
}
6564

6665
}
@@ -69,22 +68,16 @@ extension BlurBackgroundPresentable where Self: UIViewController {
6968
////////////////////////////////////////////////////////////////////////////////
7069

7170

72-
class ImageAnimationQueue: NSObject {
71+
extension UIImageView {
7372

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?) {
8174
Debug.print(#function)
8275
UIView.transition(
83-
with: imageView,
76+
with: self,
8477
duration: 0.5,
8578
options: [.beginFromCurrentState, .transitionCrossDissolve, .curveEaseIn],
8679
animations: {
87-
self.imageView.image = image
80+
self.image = image
8881
}, completion: nil
8982
)
9083
}

0 commit comments

Comments
 (0)