LoginSignup
4
2

More than 1 year has passed since last update.

[Xcode]Xcode13へアップデート後に発生したNavigationBarの不具合の対処法

Posted at

投稿経緯

業務で開発中のアプリが、Xcode13ヘアップデートした際に、NavigationBarのUIが崩れると言う不具合が発生しました。現状解消されているので共有したいと思います。

環境

macOS BigSur バージョン 11.6
Swift バージョン 5.5
Xcode バージョン 13.0

症状

pushViewControllerで遷移した先のNavigationBarに遷移元のNavigationBarのUIと遷移後のUIのふたつともが表示されUI崩れが発生するという不具合です。

対処法

どうやらiOS15ではラージタイトルだけでなくすべてのナビゲーションバーにscrollEdgeAppearanceが適用されるようになったようで、iOS15未満と同じ挙動にするにはscrollEdgeAppearanceを指定する必要があるようです。

具体的に必要なコードは以下の通り👇

let appearance = UINavigationBarAppearance()
appearance.backgroundColor = // 配色の場合
appearance.backgroundImage = // 画像の場合
appearance.titleTextAttributes = [
    .foregroundColor: UIColor.black,
    .font: UIFont.init(name: APP_FONT_LIGHT, size: 12.0) as Any
]

navigationController?.navigationBar.scrollEdgeAppearance = appearance
navigationController?.navigationBar.standardAppearance = appearance

Xcode13 × iOS15からNavigationBarの設定方法のお作法が変わったようですね。

参考にした記事

Apple ドキュメント

When running on apps that use iOS 14 or earlier, this property applies to navigation bars with large titles. In iOS 15, this property applies to all navigation bars.

お知らせ

現在、iOS開発案件を業務委託で募集中です(副業)。TwitterDMでご依頼をお待ちしています

4
2
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
4
2