7

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

iOS 15 透明标签栏

4

3 回答 3

6

在 iOS 15 中,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
}

结果: iOS 15 不透明标签栏

于 2021-06-09T07:49:52.453 回答
6

在 iOS 15 中,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 的原始颜色 在此处输入图像描述

于 2021-09-22T15:04:37.930 回答
3
init() {
    if #available(iOS 15, *) {
        let tabBarAppearance: UITabBarAppearance = UITabBarAppearance()
           tabBarAppearance.configureWithOpaqueBackground()
            UITabBar.appearance().standardAppearance = tabBarAppearance
            UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
    }
}
于 2021-09-20T16:03:11.643 回答