Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is it I can animate the change in bar tint color of a UINavigationBar but not a UITabBar?

I'm implementing a theme in my application and I ran into a weird bug (feature?). For some odd reason, I can't use UIView.animate in my custom UITabBarController class to animate a change in color of my UITabBar but the same exact code works perfectly in the custom class of my UINavigationController.

Am I missing something? Is there something else I can use to animate the color change? I've scoured the Apple Documents but found nothing.

Here is the code I'm using 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
        })
    }
}
like image 597
cyril Avatar asked Jun 07 '15 16:06

cyril


1 Answers

You can use UIView.transitionWithView to fade between the 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)
like image 54
Allan Weir Avatar answered Sep 20 '22 00:09

Allan Weir