0

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
    }
}
Chief Lutz
  • 94
  • 6
  • What happens to your CPU/Memory when it gets stuck? is it that the program is always running in a loop? or is it that it completely stops? – Michael Apr 03 '22 at 08:47
  • CPU/Memory seems fine. It is also not crashing. It looks like the standard animation gets stuck. When putting the app in the background and getting it back in front, the transition finishes. – Chief Lutz Apr 04 '22 at 07:36
  • I can't really replicate the issue from my end due to the lack of code. Have you tried returning the default animator instead of nil? – Michael Apr 04 '22 at 08:25
  • Oh there is a default Animator? Can you tell me which? Thank you! – Chief Lutz Apr 05 '22 at 08:09

1 Answers1

0

I found the cause and the solution for my problem. It is just remotely related to my custom transitions.

The issue is that the standard interactivePopGestureRecognizer of the navigationController is still enabled when the showed ViewController is the rootViewController. When then swiping back the OS gets stuck on the next push.

See this for further information and the fix: iOS App Freezes on PushViewController

Chief Lutz
  • 94
  • 6