From df0c307be4a7754ef9fa3e341e22b1aaa9dbfb3a Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Thu, 12 Oct 2017 11:13:49 -0700 Subject: [PATCH] Fixes animation when launching a game when a game is already running --- .../Segues/GamesPresentationController.swift | 16 ++++++++++------ .../Segues/GamesStoryboardSegue.swift | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Delta/Game Selection/Segues/GamesPresentationController.swift b/Delta/Game Selection/Segues/GamesPresentationController.swift index 9167fde..3f4de91 100644 --- a/Delta/Game Selection/Segues/GamesPresentationController.swift +++ b/Delta/Game Selection/Segues/GamesPresentationController.swift @@ -12,8 +12,12 @@ class GamesPresentationController: UIPresentationController { private let blurView: UIVisualEffectView - override init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?) + private let animator: UIViewPropertyAnimator + + init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?, animator: UIViewPropertyAnimator) { + self.animator = animator + self.blurView = UIVisualEffectView(effect: nil) self.blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight] @@ -26,17 +30,17 @@ class GamesPresentationController: UIPresentationController self.blurView.frame = CGRect(x: 0, y: 0, width: containerView.bounds.width, height: containerView.bounds.height) containerView.addSubview(self.blurView) - - self.presentedViewController.transitionCoordinator?.animate(alongsideTransition: { (context) in + + self.animator.addAnimations { self.blurView.effect = UIBlurEffect(style: .dark) - }) + } } override func dismissalTransitionWillBegin() { - self.presentedViewController.transitionCoordinator?.animate(alongsideTransition: { (context) in + self.animator.addAnimations { self.blurView.effect = nil - }) + } } override func dismissalTransitionDidEnd(_ completed: Bool) diff --git a/Delta/Game Selection/Segues/GamesStoryboardSegue.swift b/Delta/Game Selection/Segues/GamesStoryboardSegue.swift index 8730a01..6ccd008 100644 --- a/Delta/Game Selection/Segues/GamesStoryboardSegue.swift +++ b/Delta/Game Selection/Segues/GamesStoryboardSegue.swift @@ -48,7 +48,7 @@ extension GamesStoryboardSegue: UIViewControllerTransitioningDelegate func presentationController(forPresented presentedViewController: UIViewController, presenting presentingViewController: UIViewController?, source: UIViewController) -> UIPresentationController? { - let presentationController = GamesPresentationController(presentedViewController: presentedViewController, presenting: presentingViewController) + let presentationController = GamesPresentationController(presentedViewController: presentedViewController, presenting: presentingViewController, animator: self.animator) return presentationController } }