In my project I work with custom transitions on some views and default back to the standard one for others.
For this case I utilize the function:
navigationController(_:animationControllerFor:from:to:)
https://developer.apple.com/documentation/uikit/uinavigationcontrollerdelegate/1621846-navigationcontroller
I return my own UIViewControllerAnimatedTransitioning
or nil
when I want the standard transition, as written in the apple documentation.
Most of the time it works flawlessly.
But sometimes when returning nil
and therefore using the iOS default transition, the app gets stuck.
The next ViewController to be opened still gets willAppear
but viewDidAppear
isn't getting called and nothing happens. Also no actions are received anymore like when the main thread is blocked.
Putting the App in the background and getting back in front fixes this state and the desired VC is then shown.
Here is my code for deciding which transition should be used.
func navigationController(_ navigationController: UINavigationController,
animationControllerFor operation: UINavigationController.Operation,
from fromVC: UIViewController,
to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
switch operation {
case .push:
if let vc = toVC as? PullToCloseViewController {
self.pullInteractor = PullToCloseInteractor(attachTo: toVC)
vc.pullInteractor = self.pullInteractor
return PullToCloseAnimator(isPresenting: true)
}
return nil
case .pop:
if let vc = fromVC as? PullToCloseViewController {
return PullToCloseAnimator(isPresenting: false)
}
return nil
default:
return nil
}
}