UINavigationController subclass and transition Coordinator

We use our own subclass of UINavigationController , which displays a custom view instead of the UINavigationBar only for the first view controller.

To do this, we redefine pushViewController and popViewController for animation and in our user view.

The code for pushViewController looks like this:

 override func pushViewController(_ viewController: UIViewController, animated: Bool) { super.pushViewController(viewController, animated: animated) defer { showTopViewIfNeeded(animated: animated) } guard let transitionCoordinator = viewController.transitionCoordinator else { return } transitionCoordinator.animateAlongsideTransition(in: self.view, animation: { (context) in let fromViewController = context.viewController(forKey: UITransitionContextViewControllerKey.from) if fromViewController == self.viewControllers.first { var navigationViewFrame = self.topNavigationView.frame navigationViewFrame.origin.x -= navigationViewFrame.size.width self.topNavigationView.frame = navigationViewFrame } }, completion:nil) } 

Basically, I call the super implementation, so a transitionCoordinator is created (it's nil until I name it), and then I animate the view along with the transition.

popViewController is similar and just changes the animation (by changing the origin back to 0).

The problem I'm experiencing is that the first time the view controller is clicked, the animation does not happen. Instead, the custom view frame changes immediately.

When appearing and clicking again, the animation works fine.

To make it even weirder, it works great on iOS 9 and iOS 10 simulators, and only iOS 11 crashes.

Does my code look ok? Is there a way to interact with the transitioningCoordinator standard? I am trying to figure out if this is a problem with iOS 11 or my code.

+5
source share

Source: https://habr.com/ru/post/1272049/


All Articles