问题描述
所以我想实现从模糊到透明背景的干净导航栏过渡,反之亦然。这段代码完成了它的工作,过渡有点小问题。它仅在您使用滑动手势转到上一个视图控制器时发生。过渡到透明背景看起来应该如此,但过渡到模糊会伴随着视觉故障。
我尝试将 updatetoBlurry() 移动到 RedViewController 的 viewWillAppear,我也尝试不使用外观并将导航栏的 backgroundImage 设置为 UIImage() 或 nil,但它确实如此同样的事情。它在没有缺口的 iPhone 上更明显,但在有缺口的 iPhone 上仍然几乎看不到。我观察到它只有在嵌入 UITabBarController 时才会出现故障。
故事板设置和视频: https://imgur.com/a/W5gxdwd
代码如下:
final class NavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
navigationBar.scrollEdgeAppearance = getTransparentAppearance()
navigationBar.standardAppearance = getBlurryAppearance()
navigationBar.compactAppearance = getBlurryAppearance()
}
func updatetoTransparent() {
navigationBar.standardAppearance = getTransparentAppearance()
navigationBar.compactAppearance = getTransparentAppearance()
}
func updatetoBlurry() {
navigationBar.standardAppearance = getBlurryAppearance()
navigationBar.compactAppearance = getBlurryAppearance()
}
private func getTransparentAppearance() -> UINavigationBarappearance {
let appearance = UINavigationBarappearance()
appearance.configureWithTransparentBackground()
return appearance
}
private func getBlurryAppearance() -> UINavigationBarappearance {
let appearance = UINavigationBarappearance()
appearance.configureWithDefaultBackground()
return appearance
}
}
final class BlueViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let navigationController = navigationController as? NavigationController {
navigationController.updatetoTransparent()
}
}
override func viewWilldisappear(_ animated: Bool) {
super.viewWilldisappear(animated)
if let navigationController = navigationController as? NavigationController {
navigationController.updatetoBlurry()
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)