When adding a new controller to the navigation stack:

self.navigationController!.pushViewController(vc, animated: true) 

he leaves on the right:

enter image description here

How to make the new controller (iOS10 +) go to the left? Those. you only need to change the direction of the controller. And leave the opportunity to use the "right" appearance of the controller too. Tabbar and Navbar should remain "above", just like with the native "right" animation.

    2 answers 2

    To solve your problem there is a library Hero . With it, you can add beautiful animations to an iOS application, including when creating a new UIViewController in a UINavigationController .

    I will not describe the process of installing this library, I will just say that you can install it through CocoaPods. To work with Hero, add the following line to the beginning of the code file:

     import Hero 

    Then in the place where you are going to show the new UIViewController , set up the default animation:

     Hero.shared.defaultAnimation = HeroDefaultAnimationType.cover(direction: .right) 

    And also report that your UINavigationController is going to use the Hero library:

     self.navigationController?.hero.isEnabled = true 

    Now even when using the standard pushViewController function, you will see the expected result on the screen:

     self.navigationController?.pushViewController(vc, animated: true) 

    Something like this will happen on the screen:

    IPod dock

    • there, it seems, the screen overlaps entirely in all examples. I also need the tabbar and the navbar to remain on top - just like with the native “push” animation ... - xhr
    • @xhr Check out the updated answer. - Roman Podymov
    • It works, it is embarrassing only that for the sake of one animation it is required to add an additional dependence to the project. it would be easier to somehow do .... - xhr
    • @xhr So you can do all the animations using Hero, then it will be easier to disable them later. - Roman Podymov
    • in the sense of? Why do I need to do all the animation through Hero? I am satisfied with the standard animations, but in one single place you need to do a "reverse" animation, and for the sake of this animation you need to add a new pod to the project. Wrong it somehow) Is there really no simpler solution? But, it all works, thank you) - xhr

    Try this:

     let transition = CATransition.init() transition.duration = 0.3; transition.type = kCATransitionPush; transition.subtype = kCATransitionFromLeft; self.navigationController?.view.layer.add(transition, forKey: kCATransition) self.navigationController?.pushViewController(vc, animated: true) 
    • It works crookedly with a very strange animation ibb.co/njRSTz - xhr