My apps is currently contains the 2 UIViewController VC1 to VC2.
In VC1 is the home screen and has an orange gradient image on UINavigationBar
In VC2 has a translucent UINavigationBar
and set UIImage on UINavigationBar
but when navigation between this two view controllers, it appears a black navigation bar until the transition have done. I have try to set setNavigationBarHidden
but I do not want hide the navigation bar, so how can I remove the black navigation bar?
Like this-
In VC1
override func viewWillAppear(animated: Bool) {
if let navController = self.navigationController {
UIGraphicsBeginImageContext(gradientLayer.frame.size)
gradientLayer.renderInContext(UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIView.animateWithDuration(0.3, animations: {
navController.navigationBar.setBackgroundImage(image, forBarMetrics: .Default)
navController.navigationBar.translucent = false
})
}
}
in VC2
override func viewWillAppear(animated: Bool) {
UIView.animateWithDuration(0.3, animations: {
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = true
})
}
override func viewWillDisappear(animated: Bool) {
if let navController = self.navigationController {
UIGraphicsBeginImageContext(gradientLayer.frame.size)
gradientLayer.renderInContext(UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIView.animateWithDuration(0.3, animations: {
navController.navigationBar.setBackgroundImage(image, forBarMetrics: .Default)
navController.navigationBar.translucent = false
})
}
}
If you want to hide navigation bar without black color in transition. (It's in second screen)
Swift4:
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.setNavigationBarHidden(true, animated: true)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With