NEW: Learn to build the incredible iOS 15 Weather app today! >>

Fix NavBar in Sheet with ScrollView?

Forums > SwiftUI

I have a NavigationView that loads via sheet. THe Sheet has a ScrollView in it. When the user scrolls the NavBar changes background color. I am not sure if this is a bug or not?

I am using Xcode 13 and using iOS 15

Here is a quick video showing the issue.

Any ideas on how to fix this?

   

        // Set top Nav Bar behavior for ALL of app
    let standardAppearance = UINavigationBarAppearance()

    // Title font color
    standardAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]

    // prevent Nav Bar color change on scroll view push behind NavBar
    standardAppearance.configureWithOpaqueBackground()
    standardAppearance.backgroundColor = UIColor.blue

    self.navigationController?.navigationBar.standardAppearance = standardAppearance
    self.navigationController?.navigationBar.scrollEdgeAppearance = standardAppearance

You need to set the 'scrollEdgeAppearance' object to be the same as the 'standardAppearance' object you show above. Set it in the 'veiwDidLoad' of your ViewController.

   

Or, since this is SwiftUI, do it in your View's init or even in your App struct's init.

To add a bit more detail, this is the way navigation bars now work in iOS 15. Lots of people have had issues with this.

   

I put this on appear modiflier on first view

.onAppear {
  if #available(iOS 15.0, *) {
      let tabBarAppearance = UITabBarAppearance()
      tabBarAppearance.configureWithOpaqueBackground()
      UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
  }
}

   

Hacking with Swift is sponsored by Sentry

SPONSORED With Sentry’s error and performance monitoring for iOS, you see mobile vitals that actually matter, can solve any latency issues quickly, and learn how each release is performing over time.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.