0
votes

I have a navigation bar, which is presented modally from another view controller so the back item is not shown,

I need to cross dissolve to the second view controller, and put a navigation bar on it without putting one on the first view controller, on the navigation bar of the second view controller the back button should look exactly like system back button.

2

2 Answers

1
votes

If you have navigation bar and you need custom back button, you can add it like this:

let button = UIBarButtonItem(title: "Back Title", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(someMethod))
self.navigationItem.leftBarButtonItem = button

And in your selector you can dismiss your current viewController or call some other back method

EDIT

If you need some custom animation with standart push transition style you can do next:

For example create viewController in storyboard with SecondViewController id

At your transition action method make some like this:

func showSecondViewController() {
    guard navigationController != nil else {
        return
    }
    guard let secondViewController = storyboard?.instantiateViewControllerWithIdentifier("SecondViewController") else {
        return
    }
    navigationController!.pushViewController(secondViewController, animated: false)
    UIView.transitionWithView(navigationController!.view, duration: 1, options: .TransitionCrossDissolve, animations: nil, completion: nil)
}
0
votes

The back item would appear automatically when you push a ViewController. When you present it modally you would do it outside the initial navigation controller, therefore it's navigation would get hidden by the new one.

Edition with the proposed solution: Embed the first UIViewController in a UINavigationViewController and push the second instead of presenting it modally.