iOS10中的动画导航栏barTintColor更改无法正常工作 [英] Animate navigation bar barTintColor change in iOS10 not working
问题描述
我已升级到XCode 8.0 / iOS 10,现在导航栏的换色动画不再有效,它直接改变颜色而没有任何动画。
I upgraded to XCode 8.0 / iOS 10 and now the color change animation of my navigation bar is not working anymore, it changes the color directly without any animation.
UIView.animateWithDuration(0.2, animations: {
self.navigationController?.navigationBar.barTintColor = currentSection.color!
})
任何人都知道如何解决这个问题?
Anyone knows how to fix this?
推荐答案
要在iOS10中为navigationBar的颜色变化设置动画,您需要在动画块中设置颜色后调用 layoutIfNeeded
。
To animate navigationBar’s color change in iOS10 you need to call layoutIfNeeded
after setting color inside animation block.
示例代码:
UIView.animateWithDuration(0.5) {
self.navigationController?.navigationBar.barTintColor = UIColor.redColor()
self.navigationController?.navigationBar.layoutIfNeeded()
}
我想通知Apple 没有关闭像barTintColor这样的属性中的icialy支持动画,因此该方法可以随时中断。
Also I want to inform that Apple doesn’t officialy support animations in such properties like barTintColor, so that method can break at any time.
如果你打电话给-layoutIfNeeded动画
块期间的导航栏应该更新它的背景属性,但考虑到这些属性的性质
,真的没有任何一种
保证你可以动画其中任何一个。
If you call -layoutIfNeeded on the navigation bar during the animation block it should update its background properties, but given the nature of what these properties do, there really hasn't ever been any kind of guarantee that you could animate any of them.
这篇关于iOS10中的动画导航栏barTintColor更改无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!