Home > Blockchain >  Avoid navigation bar becoming visible when there's scrollable content beneath it
Avoid navigation bar becoming visible when there's scrollable content beneath it

Time:01-05

I have a default navigation bar on iOS 15, initially the bar itself has a tranparent background.

Default Navbar

But when I scroll the view in the view controller, to make some content of it underneath the navigation bar. Then the bar suddenly has a visible background.

With content underneath

I haven't done any special setting to my navigation bar. And tried setting scrollEdgeAppearance with no luck.

if #available(iOS 13.0, *) {
  let barAppearance = UINavigationBarAppearance()
  barAppearance.configureWithTransparentBackground()
  navigationController?.navigationBar.scrollEdgeAppearance = barAppearance
} 

CodePudding user response:

Add couple of lines to your code:

if #available(iOS 13, *) {
    let barAppearance = UINavigationBarAppearance()
    barAppearance.configureWithTransparentBackground()
    barAppearance.backgroundColor = .clear
    barAppearance.shadowColor = nil
    navigationController?.navigationBar.isTranslucent = true
    navigationController?.navigationBar.scrollEdgeAppearance = barAppearance
    navigationController?.navigationBar.standardAppearance = barAppearance
}
  •  Tags:  
  • Related