Fixes incorrect animations when presenting pause menu as well as selecting options

This commit is contained in:
Riley Testut 2017-09-26 17:21:24 -07:00
parent a592d6e2ad
commit aa5dc88114
3 changed files with 24 additions and 9 deletions

View File

@ -17,13 +17,17 @@ protocol PauseInfoProviding
class PausePresentationController: UIPresentationController class PausePresentationController: UIPresentationController
{ {
let presentationAnimator: UIViewPropertyAnimator
private let blurringView: UIVisualEffectView private let blurringView: UIVisualEffectView
private let vibrancyView: UIVisualEffectView private let vibrancyView: UIVisualEffectView
private var contentView: UIView! private var contentView: UIView!
@IBOutlet private weak var pauseLabel: UILabel!
@IBOutlet private weak var pauseIconImageView: UIImageView! // Must not be weak, or else may result in crash when deallocating.
@IBOutlet private weak var stackView: UIStackView! @IBOutlet private var pauseLabel: UILabel!
@IBOutlet private var pauseIconImageView: UIImageView!
@IBOutlet private var stackView: UIStackView!
override var frameOfPresentedViewInContainerView: CGRect override var frameOfPresentedViewInContainerView: CGRect
{ {
@ -45,8 +49,10 @@ class PausePresentationController: UIPresentationController
return frame 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.blurringView = UIVisualEffectView(effect: nil)
self.vibrancyView = UIVisualEffectView(effect: nil) self.vibrancyView = UIVisualEffectView(effect: nil)
@ -83,16 +89,18 @@ class PausePresentationController: UIPresentationController
self.contentView.alpha = 0.0 self.contentView.alpha = 0.0
self.vibrancyView.contentView.addSubview(self.contentView) self.vibrancyView.contentView.addSubview(self.contentView)
self.presentingViewController.transitionCoordinator?.animate(alongsideTransition: { context in self.presentationAnimator.addAnimations {
let blurEffect = UIBlurEffect(style: .dark) let blurEffect = UIBlurEffect(style: .dark)
self.blurringView.effect = blurEffect self.blurringView.effect = blurEffect
self.vibrancyView.effect = UIVibrancyEffect(blurEffect: blurEffect) self.vibrancyView.effect = UIVibrancyEffect(blurEffect: blurEffect)
self.contentView.alpha = 1.0 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() override func dismissalTransitionWillBegin()

View File

@ -18,7 +18,7 @@ class PauseStoryboardSegue: UIStoryboardSegue
let timingParameters = UISpringTimingParameters(mass: 3.0, stiffness: 750, damping: 65, initialVelocity: CGVector(dx: 0, dy: 0)) let timingParameters = UISpringTimingParameters(mass: 3.0, stiffness: 750, damping: 65, initialVelocity: CGVector(dx: 0, dy: 0))
self.animator = UIViewPropertyAnimator(duration: 0, timingParameters: timingParameters) 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) super.init(identifier: identifier, source: source, destination: destination)
} }

View File

@ -37,6 +37,13 @@ class PauseTransitionCoordinator: NSObject, UIViewControllerAnimatedTransitionin
destinationViewController.view.layoutIfNeeded() 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: { 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 sourceViewController.view.frame.origin.y = self.presenting ? -sourceViewController.view.bounds.height : transitionContext.containerView.bounds.height