diff --git a/Delta/Pause Menu/Presentation Controller/PausePresentationController.swift b/Delta/Pause Menu/Presentation Controller/PausePresentationController.swift index 3d1093b..c0fb79b 100644 --- a/Delta/Pause Menu/Presentation Controller/PausePresentationController.swift +++ b/Delta/Pause Menu/Presentation Controller/PausePresentationController.swift @@ -17,13 +17,17 @@ protocol PauseInfoProviding class PausePresentationController: UIPresentationController { + let presentationAnimator: UIViewPropertyAnimator + private let blurringView: UIVisualEffectView private let vibrancyView: UIVisualEffectView private var contentView: UIView! - @IBOutlet private weak var pauseLabel: UILabel! - @IBOutlet private weak var pauseIconImageView: UIImageView! - @IBOutlet private weak var stackView: UIStackView! + + // Must not be weak, or else may result in crash when deallocating. + @IBOutlet private var pauseLabel: UILabel! + @IBOutlet private var pauseIconImageView: UIImageView! + @IBOutlet private var stackView: UIStackView! override var frameOfPresentedViewInContainerView: CGRect { @@ -45,8 +49,10 @@ class PausePresentationController: UIPresentationController return frame } - override init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?) + init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?, presentationAnimator: UIViewPropertyAnimator) { + self.presentationAnimator = presentationAnimator + self.blurringView = UIVisualEffectView(effect: nil) self.vibrancyView = UIVisualEffectView(effect: nil) @@ -83,16 +89,18 @@ class PausePresentationController: UIPresentationController self.contentView.alpha = 0.0 self.vibrancyView.contentView.addSubview(self.contentView) - self.presentingViewController.transitionCoordinator?.animate(alongsideTransition: { context in - + self.presentationAnimator.addAnimations { let blurEffect = UIBlurEffect(style: .dark) self.blurringView.effect = blurEffect self.vibrancyView.effect = UIVibrancyEffect(blurEffect: blurEffect) self.contentView.alpha = 1.0 - - }, completion: nil) + } + + // I have absolutely no clue why animating with transition coordinator results in no animation on iOS 11. + // Spent far too long trying to fix it, so just use the presentation animator. + // self.presentingViewController.transitionCoordinator?.animate(alongsideTransition: { context in }, completion: nil) } override func dismissalTransitionWillBegin() diff --git a/Delta/Pause Menu/Segues/PauseStoryboardSegue.swift b/Delta/Pause Menu/Segues/PauseStoryboardSegue.swift index bec5a67..32adc40 100644 --- a/Delta/Pause Menu/Segues/PauseStoryboardSegue.swift +++ b/Delta/Pause Menu/Segues/PauseStoryboardSegue.swift @@ -18,7 +18,7 @@ class PauseStoryboardSegue: UIStoryboardSegue let timingParameters = UISpringTimingParameters(mass: 3.0, stiffness: 750, damping: 65, initialVelocity: CGVector(dx: 0, dy: 0)) self.animator = UIViewPropertyAnimator(duration: 0, timingParameters: timingParameters) - self.presentationController = PausePresentationController(presentedViewController: destination, presenting: source) + self.presentationController = PausePresentationController(presentedViewController: destination, presenting: source, presentationAnimator: self.animator) super.init(identifier: identifier, source: source, destination: destination) } diff --git a/Delta/Pause Menu/Segues/PauseTransitionCoordinator.swift b/Delta/Pause Menu/Segues/PauseTransitionCoordinator.swift index 9a83b06..6063067 100644 --- a/Delta/Pause Menu/Segues/PauseTransitionCoordinator.swift +++ b/Delta/Pause Menu/Segues/PauseTransitionCoordinator.swift @@ -37,6 +37,13 @@ class PauseTransitionCoordinator: NSObject, UIViewControllerAnimatedTransitionin destinationViewController.view.layoutIfNeeded() + if let navigationController = destinationViewController.navigationController + { + // Layout before animation to prevent strange bar button item layout during animation. + navigationController.view.setNeedsLayout() + navigationController.view.layoutIfNeeded() + } + UIView.animate(withDuration: self.transitionDuration(using: transitionContext), delay:0, options:RSTSystemTransitionAnimationCurve, animations: { sourceViewController.view.frame.origin.y = self.presenting ? -sourceViewController.view.bounds.height : transitionContext.containerView.bounds.height