iOS15 透明导航栏跳转到不透明导航栏页面的动画闪卡一下
selfcook opened this issue · 2 comments
selfcook commented
iOS15 透明导航栏跳转到不透明导航栏页面的动画闪卡一下
xiaoMing0109 commented
源码中代码片段
if (@available(iOS 15, *)) {
bar.standardAppearance = self.navigationController.navigationBar.standardAppearance;
bar.scrollEdgeAppearance = self.navigationController.navigationBar.scrollEdgeAppearance;
} else {
bar.barTintColor = self.navigationController.navigationBar.barTintColor;
[bar setBackgroundImage:[self.navigationController.navigationBar backgroundImageForBarMetrics:UIBarMetricsDefault] forBarMetrics:UIBarMetricsDefault];
bar.shadowImage = self.navigationController.navigationBar.shadowImage;
}
可以看出在 iOS 15 中仅做了获取 appearance 操作,所以这部分需要自己来写了。以下为我的示例代码,希望对你有所帮助。
/// - Note: UINavigationController
override func viewDidLoad() {
super.viewDidLoad()
if #available(iOS 15.0, *) {
let appearance = navigationBar.standardAppearance.copy()
appearance.configureWithTransparentBackground()
appearance.shadowImage = UIImage(color: .clear)
appearance.backgroundImage = UIImage(color: .clear)
navigationBar.standardAppearance = appearance
navigationBar.scrollEdgeAppearance = appearance
} else {
navigationBar.shadowImage = UIImage(color: .clear)
}
}
/// - Note: UIViewController
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let image = UIImage(color: navBarTintColor())
/// - Note: Fix iOS 15 bug.
if #available(iOS 15.0, *),
let appearance = navigationController?.navigationBar.standardAppearance {
appearance.backgroundImage = image
} else {
navigationController?.navigationBar.setBackgroundImage(image, for: .default)
}
navigationItem.title = navBarTitle()
navigationController?.navigationBar.titleTextAttributes = navBarTitleTextAttributes()
}
wokua commented
这个我重现了,提了个pullRequest,你急的话可以先用我的fork:pod 'KMNavigationBarTransition', :git =>'https://github.com/wokua/KMNavigationBarTransition'