Anchor keyboard like iMessage app when define custom transition animator in UINavigationController

187 views Asked by At

I created a custom push/pop transition in Navigation Controller. Everything is fine, except for one little fact: when I swipe back keyboard doesn't anchor to the poped view controller.

Here is some pictures to demonstrate what's happening and what do I want.

enter image description here

This happens only if I replace standard animator using UInavigationControllerDelegate method.

public func navigationController(
    _ navigationController: UINavigationController,
    animationControllerFor operation: UINavigationController.Operation,
    from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {

    return TransparentAnimator(operation: operation)
}
1

There are 1 answers

1
Felix Lapalme On

UINavigationController's default parallax transition uses private methods (that are hidden and only Apple can use) to move the keyboard like this.

Some apps still do it, like Facebook's Messenger. After playing with their transition a little I'm 99% sure they're taking a snapshot of the keyboard for their transition. If the keyboard is animating something, the animation will be paused (because it's a snapshot). Also, since they're dismissing the keyboard to achieve this effect, the keyboard will reset when the animation is cancelled (so if you're in the emoji view it will reset back to the letters).

You can see how to take a snapshot of the keyboard here: iPhone snapshot including keyboard