large Navigation Bar backGround gets clear color when swiping back to root viewController

て烟熏妆下的殇ゞ 提交于 2019-12-04 02:39:24

Try this. It should set your root View controller's navigationBar's colour to the one you wanted:

func largeNavigationTitle() {

    self.navigationController?.view.backgroundColor = VVUtility.navigationBarColor()
   //add the two lines below
    self.navigationController?.navigationBar.barTintColor = VVUtility.navigationBarColor()
    self.navigationController?.navigationBar.isTranslucent = false

    let productTitle = request?.product?.name
    self.navigationItem.title = "\(productTitle ?? " ")".localized()
    self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor : UIColor.white, NSAttributedStringKey.font : VVUtility.normalFontWithPlusSize(increaseSize: -2.0)]

    if #available(iOS 11.0, *) {
        self.navigationController?.navigationBar.prefersLargeTitles = true
        self.navigationController?.navigationBar.backgroundColor = VVUtility.splashBackGroundColor()
        self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor : UIColor.white, NSAttributedStringKey.font : VVUtility.normalFontWithPlusSize(increaseSize: 0.0)]
    } else {
        // Fallback on earlier versions
    }

}

Did you try this in your code ?

self.navigationController.navigationBar.translucent = NO;

This is actually your navigation bar changing back to the small bar mode on the bottom controller.

This is because your navigation bar is not translucent. This causes (by default) the content controller to stop at the bottom of the navigation bar. So when the navigation bar becomes small again, there is no content between its new, shorter bottom and the top of the view controller.

Your hierarchy will look like this:

Now there's a property on UIViewController that defaults to false. You can use it to specify that you want your controller's view to extend under the non-translucent bar:

extendedLayoutIncludesOpaqueBars = true

This instantly makes the hierarchy now appear as:

Now you should no longer get the gap - but you might have issues with UI elements going under the bar. You can handle that by using Safe area insets and tweaking your layout as needed, using edgesForExtendedLayout may also help depending on your layout.

TL;DR Use extendedLayoutIncludesOpaqueBars = true

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