iOS15 导航条适配

1,924 阅读1分钟

今天更新了Xcode 13 发现在iOS 15上面 导航条(有颜色的导航条返回透明导航条)会突然闪一下  查看了相关文档 发现iOS 15 上苹果改变了导航条的部分默认行为,下面是解决方法 写在didFinishLaunchingWithOptions 就可以了  


  if #available(iOS 15.0, *) {
     UINavigationBar.appearance().scrollEdgeAppearance = ({
        let navBarAppearance = UINavigationBarAppearance()
        navBarAppearance.configureWithDefaultBackground()
        navBarAppearance.backgroundColor = Color
        navBarAppearance.shadowColor = Color
        navBarAppearance.backgroundEffect = nil
        UINavigationBar.appearance().scrollEdgeAppearance = navBarAppearance
        UINavigationBar.appearance().standardAppearance = navBarAppearance
        return navBarAppearance
    })()
}