I'm trying to make the UINavigationBar
color transition smooth.
I've looked around and I'm using (this) approach.
In the ChildViewController
I have below mentioned code:
//Transition to transparent navbar
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
UIView.animate(withDuration: 0.1) {
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.barStyle = .black
self.navigationController?.navigationBar.layoutIfNeeded()
}
}
// Transition to default Navbar
override func willMove(toParentViewController parent: UIViewController?) {
self.navigationController?.navigationBar.barStyle = .default
self.navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
self.navigationController?.navigationBar.shadowImage = nil
self.navigationController?.navigationBar.barTintColor = nil
}
Resultant has flicker effect when swiped slowly from ChildViewController
to parent