我有一個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
朋友你是否設置了初始顏色? –
我試過你的代碼,它工作正常。顏色爲所有三個動畫... –