We are using a custom subclass of UINavigationController that displays a custom view instead of the UINavigationBar only for the first view controller.
For that, we override pushViewController and popViewController to animate out and in our custom view.
The code for pushViewController looks like:
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 gets created (it's nil until I call that), and then I animate the view alongside the transition.
The popViewController is similar and just reverses the animation (by changing the origin back o zero).
The problem I experience, is that the first time a view controller is pushed, the animation doesn't happen. Instead, the frame of the custom view changes immediately.
Upon popping, and pushing again, the animation works perfectly.
To make it even weirder, this works fine in iOS 9 and iOS 10 simulators, and only fails in iOS 11.
Does my code look ok? Is the way I'm interacting with the transitioningCoordinator standard? I'm trying to understand if this is an iOS 11 issue, or my code's.