在 iOS 15 上,当导航到具有透明导航栏的视图控制器时,透明栏的动画无法按预期工作。
但是,如果您使用透明导航栏导航回视图控制器,动画将按预期工作。
这就是我设置视图控制器的方式:
根VC
let appearance = UINavigationBarAppearance()
appearance.configureWithDefaultBackground()
appearance.backgroundColor = UIColor.red
self.navigationController?.navigationBar.standardAppearance = appearance
self.navigationController?.navigationBar.scrollEdgeAppearance = self.navigationController?.navigationBar.standardAppearance
第一VC
let appearance = UINavigationBarAppearance()
appearance.configureWithTransparentBackground()
self.navigationController?.navigationBar.standardAppearance = appearance
self.navigationController?.navigationBar.scrollEdgeAppearance = self.navigationController?.navigationBar.standardAppearance
第二个VC
let appearance = UINavigationBarAppearance()
appearance.configureWithDefaultBackground()
appearance.backgroundColor = UIColor.yellow
self.navigationController?.navigationBar.standardAppearance = appearance
self.navigationController?.navigationBar.scrollEdgeAppearance = self.navigationController?.navigationBar.standardAppearance
请注意,在以下示例中,从secondVC -> firstVC但不是从rootVC -> firstVC过渡是多么平滑:
示例项目:https ://github.com/karlingen/NavigationTest
任何想法为什么它会这样?