UINavigationController hide only navigationBar - Back animation issue

给你一囗甜甜゛ 提交于 2019-12-02 11:40:45

In First viewController, also set the backgroundImage and shadowImage of navigationBar as nil, i.e.

class FirstVC: UIViewController
{
    override func viewWillAppear(_ animated: Bool)
    {
        super.viewWillAppear(animated)
        self.navigationController?.navigationBar.isTranslucent = true
        self.navigationController?.navigationBar.setBackgroundImage(nil, for: UIBarMetrics.default)
        self.navigationController?.navigationBar.shadowImage = nil
        self.navigationController?.navigationBar.barTintColor = .red
        self.navigationController?.navigationBar.tintColor = UIColor.white
        self.navigationController?.navigationBar.barStyle = .black
    }
}

class SecondVC: UIViewController
{
    override func viewWillAppear(_ animated: Bool)
    {
        super.viewWillAppear(animated)

        self.navigationController?.navigationBar.isTranslucent = true
        self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
        self.navigationController?.view.backgroundColor = UIColor.clear
        self.navigationController?.navigationBar.shadowImage = UIImage()
    }
}

You should hide Navigation Controller's Navigation Bar and use custom navigation Bar using UIView. I think it will solve your issue.

First viewController is showing with black nav bar for short duration on quick transition because of background color of UIWindow on which navigaion-bar transitions are happening. Simply, add this line in your didFinishLaunchingWithOptions: method of AppDelegate

window?.backgroundColor = Constants.kThemeRedColor

And you are done. Happy coding!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!