2017-02-16 3 views
4

私はFirstViewControllerSecondViewControllerを持っています。彼らはUINavigationBarの色が異なっています。 SecondViewControllerと表示すると、色が細かくフェードします。私は、シミュレータと遅いアニメーションでアニメーションを記録しました。しかしUINavigationBar UIViewControllerを却下したときの奇妙な色の変化のアニメーション

Animation Show

、私はFirstViewControllerに戻っSecondViewControllerから行く、色をアニメーション化しないとすべてが一度だけで変わります。

Animation Dismiss

これは私がSecondViewControllerUINavigationBarためのコードを設定する方法です。私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 

    } 
} 

私もSecondViewControllerviewWillDisappearにUINavigationBar情報を変更しようとしましたが、それは同じ効果を持っていました。

また、backgroundColorを設定しようとしましたが、何も変更していませんでした。

最初のアニメーションと同じように2番目のアニメーションを取得するにはどうすればよいですか?

更新

セグエSecondViewControllerに一種のショーです。

私は単に私はそれがデフォルトUINavigationController実装だ、バックボタンに任意のカスタムコードを追加していないself.performSegue(withIdentifier: "SecondViewControllerSegue", sender: nil)

でそれを呼び出します。

+0

あなたの質問に間違いがありましたが、私は答えを削除しました。 FirstViewControllerのviewWillAppearメソッドで単にnavBarSettingsから値を設定するのではなく、手動で値を設定しようとしましたか? –

+0

はい、私はしましたが、違いはありません – Yannick

+0

SecondViewControllerをどのようにプッシュし、どのようにポップするかというコードで質問を更新できますか? –

答えて

2

戻るボタンをカスタムの戻るボタンに置​​き換えて、アクションを追加してください。

let backButton = UIButton() 
backButton.addTarget(self, action: #selector(self.backButtonClicked), for: UIControlEvents.touchUpInside) 
navBar.navigationItem.leftBarButtonItem = barButton 

func backButtonClicked() { 
    // try implementing the same thing here but with the self.navigationController?.popViewController(animated: true) 
} 
+1

ありがとうございました!:) 'self.navigationController?.popViewController(animated:true)'の部分がトリックでした – Yannick

+2

よろしくお願いします。ハッピーコーディング。 –

関連する問題