它是如何,我可以动画在UINavigationBar的条形色调颜色的变化,但不是的UITabBar? [英] How is it I can animate the change in bar tint color of a UINavigationBar but not a UITabBar?
问题描述
我在实现我的应用程序一个主题,我遇到了一个奇怪的错误(功能?)。对于一些奇怪的原因,我无法使用 UIView.animate
在我的自定义的UITabBarController类的动画在我的UITabBar但颜色变化完全相同code完美的作品在自定义类我的UINavigationController的。
我缺少的东西吗?有没有别的东西我可以用动画的颜色变化?我已经走遍了苹果的文件,但一无所获。
下面是code我使用的是在两种情况下:
类customNavigationController:{的UINavigationController
@IBOutlet弱VAR导航栏= ThemeManager.navigationbar FUNC黄昏(通知:NSNotification){
UIView.animateWithDuration(1,动画:{
?self.navBar .barTintColor =的UIColor(红色:255分之79,绿色环保:255分之79,蓝:二百五十五分之七十九,阿尔法:1)
self.navBar?.barStyle = UIBarStyle.Black })
}
}
和
类customTabController:{的UITabBarController
@IBOutlet弱VAR选项卡= ThemeManager.tabbar FUNC黄昏(通知:NSNotification){
UIView.animateWithDuration(1,动画:{
self.tab?.barTintColor =的UIColor(红色:255分之79,绿色环保:255分之79,蓝:二百五十五分之七十九,阿尔法:1)
self.tab?.barStyle = UIBarStyle.Black
})
}
}
您可以使用UIView.transitionWithView在两种状态之间褪色
UIView.transitionWithView(self.tab!时间:1.0,选择:.BeginFromCurrentState | .TransitionCrossDissolve,动画:{() - GT;无效的
!self.tab .barTintColor =的UIColor(红色:255分之79,绿色环保:255分之79,蓝:二百五十五分之七十九,阿尔法:1)
self.tab!.barStyle = UIBarStyle.Black
}完成:无)
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
})
}
}
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)
这篇关于它是如何,我可以动画在UINavigationBar的条形色调颜色的变化,但不是的UITabBar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!