Панель вкладок iOS 15 прозрачна после прокрутки вниз
4 ответа
В iOS 15 UIKit расширил использование scrollEdgeAppearance, которое по умолчанию создает прозрачный фон.
Поскольку я глобально изменил цвет панели вкладок в своем приложении, до iOS 15 я добавил в свой AppDelegate следующий код:
UITabBar.appearance().barTintColor = "YOUR UITABBAR COLOR"
UITabBar.appearance().tintColor = "YOUR ICONS COLOR"
UITabBar.appearance().isTranslucent = true
Чтобы восстановить старый внешний вид, мне пришлось использовать новые API внешнего вида UITBar, UITabBarAppearance. Я изменил свой код на:
UITabBar.appearance().barTintColor = "YOUR UITABBAR COLOR"
UITabBar.appearance().tintColor = "YOUR ICONS COLOR"
UITabBar.appearance().isTranslucent = true
if #available(iOS 15.0, *) {
let appearance = UITabBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = "YOUR UITABBAR COLOR"
UITabBar.appearance().standardAppearance = appearance
UITabBar.appearance().scrollEdgeAppearance = UITabBar.appearance().standardAppearance
}
В iOS 15 Apple добавляет
scrollEdgeAppearance
свойство для настройки внешнего вида панели вкладок при прокрутке края.
Чтобы исправить прозрачную панель вкладок, вы должны создать настраиваемый внешний вид края прокрутки и установить его на панель вкладок.
if #available(iOS 15.0, *) {
let appearance = UITabBarAppearance()
appearance.backgroundEffect = UIBlurEffect(style: .light)
tabBar.scrollEdgeAppearance = appearance
}
init() {
if #available(iOS 15, *) {
let tabBarAppearance: UITabBarAppearance = UITabBarAppearance()
tabBarAppearance.configureWithOpaqueBackground()
UITabBar.appearance().standardAppearance = tabBarAppearance
UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
}
}
Как объяснили другие, вы должны включить и настроитьscrollEdgeAppearance
свойство.
Вот как это сделать наstoryboard
:
он добавит целый раздел свойств внешнего вида края прокрутки: