gpt4 book ai didi

ios - subview 背景颜色没有动画

转载 作者:行者123 更新时间:2023-11-30 12:40:01 25 4
gpt4 key购买 nike

我有一个 UIViewController,其中包含一个呈现波形的 subview 。当按下按钮时,我试图让主 UIView、 subview 和导航栏从白色变为灰色。我已经能够更改主视图和导航栏,但无法弄清楚如何更改波形的 subview 。现在, subview 立即变为灰色,而不是与其他 View 和导航栏同步动画。

//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)

这会导致波形 View 和导航栏同步动画,但在其他两个 View 完成动画后,self.view 立即变为深灰色...

最佳答案

我做动画的想法是这样的

Objective-C

//Set Initial frame or color here & then write block for animation

[UIView animateWithDuration:1.0f animations:^{

// Now set your changing animation frame or color here

}completion:^(BOOL finished) {

//Do completion stuff here

}];

如果你打算通过 anyView.layer.backgroundColor 设置它然后#import <QuartzCore/QuartzCore.h>

swift

//Set Initial frame or color here & then write block for animation

UIView.animate(withDuration: 5.0, animations: {

// Now set your changing animation frame or color here
self.view.layer.backgroundColor = UIColor(red: 20.00/255, green: 20.00/255, blue: 20.00/255, alpha: 1.00).cgColor

}, completion: { finished in

//do completion stuffs
})

如果你打算通过 anyView.layer.backgroundColor 设置它然后import QuartzCore

关于ios - subview 背景颜色没有动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42337788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com