【问题标题】:iOS 15 tab bar transparent after scrolling to the bottomiOS 15标签栏滚动到底部后透明
【发布时间】:2021-08-26 04:50:13
【问题描述】:

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

【问题讨论】:

    标签: tabbar ios15


    【解决方案1】:

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

    结果:

    【讨论】:

      【解决方案2】:
      init() {
          if #available(iOS 15, *) {
              let tabBarAppearance: UITabBarAppearance = UITabBarAppearance()
                 tabBarAppearance.configureWithOpaqueBackground()
                  UITabBar.appearance().standardAppearance = tabBarAppearance
                  UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
          }
      }
      

      【讨论】:

      • 这个答案很有用。
      【解决方案3】:

      在 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-11-05
      • 1970-01-01
      • 2021-12-24
      • 1970-01-01
      • 2013-11-27
      • 1970-01-01
      • 2019-06-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多