How can I animate the color change of the hue of a stroke in a UINavigationBar but not a UITabBar?

I am using a theme in my application and I came across a strange error (function?). For some odd reason, I can't use UIView.animate in my custom UITabBarController class to animate the color change of my UITabBar, but the same exact code works fine in the custom class of my UINavigationController.

Am I missing something? Is there anything else I can use to animate color changes? I looked at Apple docs but found nothing.

Here is the code that I use in both cases:

 class customNavigationController: UINavigationController { @IBOutlet weak var navBar = ThemeManager.navigationbar func dusk(notification: NSNotification) { UIView.animateWithDuration(1, animations: { self.navBar?.barTintColor = UIColor(red: 79/255, green: 79/255, blue: 79/255, alpha: 1) self.navBar?.barStyle = UIBarStyle.Black }) } } 

and

 class customTabController: UITabBarController { @IBOutlet weak var tab = ThemeManager.tabbar func dusk(notification: NSNotification) { UIView.animateWithDuration(1, animations: { self.tab?.barTintColor = UIColor(red: 79/255, green: 79/255, blue: 79/255, alpha: 1) self.tab?.barStyle = UIBarStyle.Black }) } } 
+7
ios animation swift uitabbarcontroller uinavigationcontroller
source share
2 answers

You can use UIView.transitionWithView to switch between two states

 UIView.transitionWithView(self.tab!, duration: 1.0, options: .BeginFromCurrentState | .TransitionCrossDissolve, animations: { () -> Void in self.tab!.barTintColor = UIColor(red: 79/255, green: 79/255, blue: 79/255, alpha: 1) self.tab!.barStyle = UIBarStyle.Black }, completion: nil) 
+9
source share

It’s good to change the color on the tab bar personally, I use a completely different image with different colors enter image description here

As you can see, my selected image is my second image. Right now he won’t show this image unless I add it to my Runtime User Defined Attributes

enter image description here

Set the path to the "selectedImage" key, the type of "Image" and the value for your image that you want to display when presenting. Hope this answers your question.

0
source share

All Articles