私はFirstViewController
とSecondViewController
を持っています。彼らはUINavigationBar
の色が異なっています。 SecondViewController
と表示すると、色が細かくフェードします。私は、シミュレータと遅いアニメーションでアニメーションを記録しました。しかしUINavigationBar UIViewControllerを却下したときの奇妙な色の変化のアニメーション
、私はFirstViewController
に戻っSecondViewController
から行く、色はをアニメーション化しないとすべてが一度だけで変わります。
これは私がSecondViewController
にUINavigationBar
ためのコードを設定する方法です。私FirstViewController
クラスで
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let navBar = self.navigationController?.navigationBar {
navBar.barStyle = UIBarStyle.black
navBar.barTintColor = NavBarColor.red
navBar.backgroundColor = NavBarColor.red
navBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
navBar.isTranslucent = false
navBar.tintColor = .white
}
}
、私は構造体NavBarSettings
を作成し、UINavigationBarの情報を保存します。私はviewWillAppear
にそれらを適用します。
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let navBar = self.navigationController?.navigationBar,
let navBarSettings = self.navBarSettings {
navBar.barStyle = navBarSettings.barStyle
navBar.barTintColor = navBarSettings.barTintColor
navBar.backgroundColor = navBarSettings.backgroundColor
navBar.titleTextAttributes = navBarSettings.titleTextAttributes
navBar.isTranslucent = navBarSettings.isTranslucent
navBar.tintColor = navBarSettings.tintColor
}
}
私もSecondViewController
viewWillDisappear
にUINavigationBar情報を変更しようとしましたが、それは同じ効果を持っていました。
また、backgroundColor
を設定しようとしましたが、何も変更していませんでした。
最初のアニメーションと同じように2番目のアニメーションを取得するにはどうすればよいですか?
更新が
セグエSecondViewController
に一種のショーです。
私は単に私はそれがデフォルトUINavigationController
実装だ、バックボタンに任意のカスタムコードを追加していないself.performSegue(withIdentifier: "SecondViewControllerSegue", sender: nil)
でそれを呼び出します。
あなたの質問に間違いがありましたが、私は答えを削除しました。 FirstViewControllerのviewWillAppearメソッドで単にnavBarSettingsから値を設定するのではなく、手動で値を設定しようとしましたか? –
はい、私はしましたが、違いはありません – Yannick
SecondViewControllerをどのようにプッシュし、どのようにポップするかというコードで質問を更新できますか? –