NavigationController: finish current transition before setViewControllers

This commit is contained in:
Peter 2019-05-09 14:58:31 +02:00
parent 3417ed445c
commit df839bd80b
2 changed files with 31 additions and 2 deletions

View File

@ -966,6 +966,9 @@ open class NavigationController: UINavigationController, ContainableController,
} }
let previousControllers = self._viewControllers let previousControllers = self._viewControllers
self._viewControllers = resultControllers self._viewControllers = resultControllers
if let navigationTransitionCoordinator = self.navigationTransitionCoordinator {
navigationTransitionCoordinator.complete()
}
if let layout = self.validLayout { if let layout = self.validLayout {
self.updateControllerLayouts(previousControllers: previousControllers, layout: layout, transition: animated ? .animated(duration: 0.5, curve: .spring) : .immediate) self.updateControllerLayouts(previousControllers: previousControllers, layout: layout, transition: animated ? .animated(duration: 0.5, curve: .spring) : .immediate)
} }

View File

@ -38,6 +38,7 @@ class NavigationTransitionCoordinator {
private let inlineNavigationBarTransition: Bool private let inlineNavigationBarTransition: Bool
private(set) var animatingCompletion = false private(set) var animatingCompletion = false
private var currentCompletion: (() -> Void)?
init(transition: NavigationTransition, container: UIView, topView: UIView, topNavigationBar: NavigationBar?, bottomView: UIView, bottomNavigationBar: NavigationBar?) { init(transition: NavigationTransition, container: UIView, topView: UIView, topNavigationBar: NavigationBar?, bottomView: UIView, bottomNavigationBar: NavigationBar?) {
self.transition = transition self.transition = transition
@ -148,6 +149,8 @@ class NavigationTransitionCoordinator {
} }
func animateCancel(_ completion: @escaping () -> ()) { func animateCancel(_ completion: @escaping () -> ()) {
self.currentCompletion = completion
UIView.animate(withDuration: 0.1, delay: 0.0, options: UIViewAnimationOptions(), animations: { () -> Void in UIView.animate(withDuration: 0.1, delay: 0.0, options: UIViewAnimationOptions(), animations: { () -> Void in
self.progress = 0.0 self.progress = 0.0
}) { (completed) -> Void in }) { (completed) -> Void in
@ -173,13 +176,33 @@ class NavigationTransitionCoordinator {
self.endNavigationBarTransition() self.endNavigationBarTransition()
completion() if let currentCompletion = self.currentCompletion {
self.currentCompletion = nil
currentCompletion()
}
}
}
func complete() {
self.animatingCompletion = true
self.progress = 1.0
self.dimView.removeFromSuperview()
self.shadowView.removeFromSuperview()
self.endNavigationBarTransition()
if let currentCompletion = self.currentCompletion {
self.currentCompletion = nil
currentCompletion()
} }
} }
func animateCompletion(_ velocity: CGFloat, completion: @escaping () -> ()) { func animateCompletion(_ velocity: CGFloat, completion: @escaping () -> ()) {
self.animatingCompletion = true self.animatingCompletion = true
let distance = (1.0 - self.progress) * self.container.bounds.size.width let distance = (1.0 - self.progress) * self.container.bounds.size.width
self.currentCompletion = completion
let f = { let f = {
/*switch self.transition { /*switch self.transition {
case .Push: case .Push:
@ -201,7 +224,10 @@ class NavigationTransitionCoordinator {
self.endNavigationBarTransition() self.endNavigationBarTransition()
completion() if let currentCompletion = self.currentCompletion {
self.currentCompletion = nil
currentCompletion()
}
} }
if abs(velocity) < CGFloat.ulpOfOne && abs(self.progress) < CGFloat.ulpOfOne { if abs(velocity) < CGFloat.ulpOfOne && abs(self.progress) < CGFloat.ulpOfOne {