我正在我的应用程序中实现一个主题,但我遇到了一个奇怪的错误(功能?)。出于某些奇怪的原因,我无法在我的自定义 UITabBarController 类中使用 UIView.animate
来为我的 UITabBar 的颜色变化设置动画,但相同的代码在我的 UINavigationController 的自定义类中可以完美运行。
我错过了什么吗?还有什么我可以用来制作颜色变化的动画吗?我已经搜索了 Apple 文档,但一无所获。
这是我在这两种情况下使用的代码:
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
})
}
}
和:
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)
关于ios - 我如何可以动画化 UINavigationBar 而不是 UITabBar 的条形色调颜色的变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30695969/