我正在我的应用程序中实现一个主题,但遇到了一个奇怪的错误(功能?)。由于某些奇怪的原因,我无法使用UIView.animate
在我的自定义 UITabBarController 类中,对 UITabBar 的颜色变化进行动画处理,但相同的代码在我的 UINavigationController 的自定义类中完美运行。
我错过了什么吗?我还可以使用其他东西来动画颜色变化吗?我翻遍了苹果文档,但一无所获。
这是我在两种情况下使用的代码:
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
})
}
}
您可以使用 UIView.transitionWithView 在两种状态之间淡入淡出
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)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)