Search code examples
iosswiftanimationuinavigationcontrolleruinavigationbar

Additional navigation bar slides from top on modal segue push


The first screen of my iOS app is a login screen + a register button located at the bottom. It is embedded in a navigation view controller although the navigation bar becomes invisible until successful login when next screen slides in from the right. This works fine.

The problem is when the registration view (modal) slides up after the register button is tapped. Register view is embedded in another navigation controller and it includes the navigation bar at the top of it's sliding view. At the same time, from the top, second navigation bar (empty) slides down too. The second navigation bar is immediately covered by the modal view but for a moment the screen flickers, which is annoying.

How to prevent the additional navigation bar to slide down from the top? enter image description here


Solution

  • I found the bug!

    The login view controller had the method:

    override func viewWillDisappear(_ animated: Bool) {
        navigationController?.setNavigationBarHidden(false, animated: animated)
        super.viewWillDisappear(animated)
    }
    

    It was necessary to recover navigation bar in the after-login view controller but was making the annoying effect in registration view controller. So I deleted it, and instead, I inserted the snippet to after-login view-controller:

    override func viewWillAppear(_ animated: Bool) {
        navigationController?.setNavigationBarHidden(false, animated: animated)
        super.viewWillAppear(animated)
    }