I have three view controllers embedded within a UINavigationController
. FirstViewController
navigates to SecondTableViewController
, which navigates to ThirdDetailViewController
.
The problem I am having is when customising the style of the status bar
and UINavigationBar
using the scrollViewDidScroll
method within the SecondTableViewController
it also override the other view controllers within the stack that come after it as well as all status bar styles.
Does anybody know how I can prevent the scrollViewDidScroll method from effecting other view controllers within the stack ?
FirstViewController
override func viewWillAppear(animated: Bool) {
UIApplication.sharedApplication().statusBarStyle = .Default
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarPosition: .Any, barMetrics: .Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.backgroundColor = UIColor.whiteColor()
self.navigationController?.navigationBar.tintColor = UIColor.blackColor()
self.navigationController?.navigationBar.barTintColor = UIColor.whiteColor()
self.navigationController?.navigationBar.translucent = true
}
SecondTableViewController
I change the style of the navigation depending on how far down the user has scrolled to either blend in or stand out from the content.
The style of other view controllers change to whichever style is set in the method.
override func scrollViewDidScroll(scrollView: UIScrollView) {
let color = colorWheel()
if (scrollView.contentOffset.y > -60) {
UIApplication.sharedApplication().statusBarStyle = .Default
self.navigationController?.navigationBar.setBackgroundImage(nil, forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.backgroundColor = UIColor.whiteColor()
self.navigationController?.navigationBar.tintColor = color.appColor
self.navigationController?.navigationBar.barTintColor = UIColor.whiteColor()
self.navigationController?.view.backgroundColor = color.appColor
self.navigationController?.navigationBar.translucent = true
} else {
UIApplication.sharedApplication().statusBarStyle = .LightContent
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.backgroundColor = UIColor.clearColor()
self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
self.navigationController?.navigationBar.barTintColor = UIColor.clearColor()
self.navigationController?.view.backgroundColor = UIColor.clearColor()
self.navigationController?.navigationBar.translucent = true
}
}
ThirdDetailViewController
override func viewWillAppear(animated: Bool) {
UIApplication.sharedApplication().statusBarStyle = .Default
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarPosition: .Any, barMetrics: .Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.backgroundColor = UIColor.whiteColor()
self.navigationController?.navigationBar.tintColor = UIColor.blackColor()
self.navigationController?.navigationBar.barTintColor = UIColor.whiteColor()
self.navigationController?.navigationBar.translucent = true
}