Search code examples
iosswiftuinavigationcontrolleruitabbarcontrolleruinavigationbar

Strange animation on the navigation bar during push


I has a storyboard like below.

Storyboard

When i taped “Push ViewController 2”, a strange animation has appeared.

Strange animation on navigation bar

I set NavigationController.view.backgroundColor or TabBarController.view.background to white. But it does not working. I don’t want to set navigationBar.translucent to NO.

How can I get rid of it?


Solution

  • When you using a NavigationController in TabView application. Its a common practice to embed a NavigationController separately to each of your ViewController to avoid unusual behaviour and also it gives you a better way to control your NavigationController in seperate instance. Following Storyboard layout fix your strange animation.

    enter image description here

    Output:

    enter image description here

    PS: Same idea also mentioned by @skJosh comment.

    Update: Paste below code into your DetailViewController to hide and unhide your TabBar.

    override func viewWillAppear(_ animated: Bool) {
        tabBarController?.tabBar.isHidden = true
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        tabBarController?.tabBar.isHidden = false
    }