本記事について
iOS15でスクロール時にタブバーが黒くなる問題について、対処法をご紹介します。
環境
- Xcode13.0
- iOS15のシミュレータ
発生した問題
アプリをビルドした後、スクロール時、以下のようにタブバーが黒に変更されてしまう。
(詳細に言うと、初回起動時は通常の色だが、スクロールすると色が変わってしまう)
ちなみに、iOS14の場合は問題なかった。
解決策
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)
皆さんの参考になれば幸いです。