我有一个UIViewController
包含呈现波形的子视图。当按下按钮时,我试图让主要UIView
,子视图和导航栏从白色变为灰色。我已经能够改变主视图和导航栏,但无法弄清楚如何让波形的子视图改变。现在,子视图立即变为灰色,而不是与其他视图和导航栏同步动画。子视图背景颜色不动画
//View Controller Code
UIView.animate(withDuration: 10.0, animations: {
self.navigationController?.navigationBar.barTintColor = UIColor(red: 20.00/255, green: 20.00/255, blue: 20.00/255, alpha: 1.00)
self.navigationController?.navigationBar.layoutIfNeeded()
self.waveform.backgroundColor = UIColor(red: 20.00/255, green: 20.00/255, blue: 20.00/255, alpha: 1.00)
self.view.backgroundColor = UIColor(red: 20.00/255, green: 20.00/255, blue: 20.00/255, alpha: 1.00)
}, completion: { finished in
//do stuff
})
//waveform view
override init(frame: CGRect) {
super.init(frame: frame)
self.setup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setup()
}
override func draw(_ rect: CGRect) {
for i in 0..<self.circles.count {
self.draw(self.circles[i], ratio: -1.0)
self.draw(self.circles[i], ratio: 1.0)
}
}
func update(_ level: Double) {
amplitude = fmin(normalizedPowerLevelFromDecibels(level), maxAmplitude)
setNeedsDisplay()
}
//更新后的动画
UIView.transition(with: self.view, duration: 1.0, options: [.transitionCrossDissolve], animations: {
self.view.backgroundColor = UIColor(red: 20.00/255, green: 20.00/255, blue: 20.00/255, alpha: 1.00)
self.navigationController?.navigationBar.barTintColor = UIColor(red: 20.00/255, green: 20.00/255, blue: 20.00/255, alpha: 1.00)
self.navigationController?.navigationBar.layoutIfNeeded()
self.waveform.backgroundColor = UIColor(red: 20.00/255, green: 20.00/255, blue: 20.00/255, alpha: 1.00)
}, completion: nil)
这会导致波形视图和导航栏同步动画,但self.view
改变深灰色另外两个意见完成后,动画瞬间...
无法从上面的代码块中获得一个想法,请您与[email protected]分享您的项目,然后我会尝试找出问题 – arunjos007
朋友你是否设置了初始颜色? –
我试过你的代码,它工作正常。颜色为所有三个动画... –