LoginSignup
2
1

More than 1 year has passed since last update.

iOS15でスクロール時にタブバーが黒くなる問題を解消したい

Last updated at Posted at 2021-11-02

本記事について

iOS15でスクロール時にタブバーが黒くなる問題について、対処法をご紹介します。

環境

  • Xcode13.0
  • iOS15のシミュレータ

発生した問題

アプリをビルドした後、スクロール時、以下のようにタブバーが黒に変更されてしまう。
(詳細に言うと、初回起動時は通常の色だが、スクロールすると色が変わってしまう)

ちなみに、iOS14の場合は問題なかった。

スクリーンショット 2021-11-02 14.57.53.png

解決策

iOS15で仕様が変わっているとのこと。
原因は、UITabBarAppearanceのscrollEdgeAppearanceプロパティを明示的に設定する必要があること。
画面のスクロール中と、スクロールが終端に達した時のタブバーの色を変更できるらしい。
https://developer.apple.com/documentation/uikit/uitabbar/3750912-scrolledgeappearance

今回自分の場合は以下のように修正しました。

guard let tabBarController = tabBarController else { return }
let tabBarAppearance = UITabBarAppearance()
tabBarAppearance.backgroundColor = .white
tabBarController.tabBar.standardAppearance = tabBarAppearance

if #available(iOS 15.0, *) { // 新たに追加
    tabBarController.tabBar.scrollEdgeAppearance = tabBarAppearance
}

最後に

バージョンアップ時にRelase notesに目を通すべきでした...

UITabBar and UIToolbar inspectors now support configuring scrollEdgeAppearance.(71788169)

皆さんの参考になれば幸いです。

参考記事

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1