Search code examples
swift3uinavigationcontrollerpresentviewcontroller

How to change the way in which the root controller of a navigation controller is appearing on screen?


The navigation controller is not the initial view controller. It is being instantiated in the initial VC and supplied with a root controller, the second VC. When I call present view controller function I cannot change the way in which this new VC in being presented, it always appears from the bottom. I did not find how to make it come from right to left. I tried to change who gets the call to modalPresentaionStyle from the second VC to the nav con and back but no change. Code listing below. Thank you for your help.

@objc fileprivate func showRegisterScreen() { 
    let registerAccountVC = RegisterAccountVC()
    let navigationController = UINavigationController(rootViewController: registerAccountVC)
    navigationController.modalPresentationStyle = .pageSheet
    present(navigationController, animated: true, completion: nil)
}

Solution

  • This will add a custom animation from right to left.

    let transition = CATransition.init()
    transition.duration = 0.4
    transition.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionEaseInEaseOut)
    transition.type = kCATransitionPush
    transition.subtype = kCATransitionFromRight
    view.window?.layer.add(transition, forKey: nil)
    present(navigationController, animated: false, completion: nil)