iOS 15 标签栏滚动到底部后透明

iOS 15 tab bar transparent after scrolling to the bottom

如何解决iOS 15 标签栏滚动到底部后透明:

在 iOS15 中,Apple 添加了 scrollEdgeAppearance 属性 用于在边缘滚动时配置标签栏的外观。

https://developer.apple.com/documentation/uikit/uitabbar/3750912-scrolledgeappearance?changes=latest_minor

要修复透明标签栏,您应该创建自定义滚动边缘外观并将其设置到标签栏。

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
    }
}

在 iOS15 中,UIKit 扩展了 scrollEdgeAppearance 的使用,它默认产生透明背景。

由于我在 iOS 15 之前在我的应用程序中全局更改了标签栏颜色,因此我将以下代码添加到我的 AppDelegate 中:

UITabBar.appearance().barTintColor = "YOUR UITABBAR COLOR"
UITabBar.appearance().tintColor = "YOUR ICONS COLOR"
UITabBar.appearance().isTranslucent = true

为了恢复旧的外观,我采用了新的 UITBar 外观 API,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
    }

结果,我得到了我的 UITabBar 的原始颜色