ios - UINavigationController 过渡到 defaultBackground 显示白色边框
问题描述
所以我想实现从模糊到透明背景的干净导航栏过渡,反之亦然。这段代码完成了它的工作,转换有点小故障。仅当您使用滑动手势转到上一个视图控制器时才会发生这种情况。过渡到应有的透明背景外观,但过渡到模糊会伴随视觉故障。
我尝试将updateToBlurry()移动到RedViewController 的viewWillAppear并且我也尝试不使用外观并将 navigationBar 的 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()
}
}
}
解决方案
推荐阅读
- jquery - 动态表创建中的Jquery if语句
- c# - WPF XAML 组合框在更新 ItemsSource 时与实际值同步
- ios - 如何将 UITabBarController 导航到 ViewController?
- nginx - /some/folder的Nginx 403目录索引被禁止
- php - Xdebug PHP 7.1 PhpStorm 远程服务器与 Docker。如何?
- maven - 使用 ansible maven_artifact 获取 jar-with-dependencies
- javascript - Ionic&Angular&Bugsnag - 自定义错误处理程序和异步 AppVersion
- java - Jackson Java 8 LocalDateTime 与 nanos 的序列化
- reactjs - 使用 Jest 测试反应时未在测试中调用模拟函数
- javascript - onchange js不能在yii2 php select中工作