我有UIProgressView
。在开始UITextField
的文本编辑时,我将进度条的值设置为1。在此之前,我将它提升到0.1。但它只是设置进度一次。如果我先将进度设置为0.1,那么在它没有将进度设置为1.请告诉我这是什么问题?
func textFieldDidBeginEditing(_ textField: UITextField) {
setViewBottomColor()
var view:BottomView?
if textField == textFieldEmail {
view = self.bottomViewFirst
view?.trackTintColor = Constant.AppColor.viewBottom
view?.progressTintColor = Constant.AppColor.purpleViewColor
}
else if textField == textFieldPassword {
view = self.bottomViewSecond
view?.trackTintColor = Constant.AppColor.viewBottom
view?.progressTintColor = Constant.AppColor.purpleViewColor
}
if view != nil {
view?.setProgress(1, animated: true)
UIView.animate(withDuration: 1.0, animations: {
view?.layoutIfNeeded()
}, completion: { (finish) in
})
}
}
func setViewBottomColor() {
self.bottomViewFirst.trackTintColor = Constant.AppColor.viewBottom
self.bottomViewFirst.progressTintColor = Constant.AppColor.purpleViewColor
self.bottomViewFirst?.setProgress(0.1, animated: false)
self.bottomViewFirst?.layoutIfNeeded()
}
答案 0 :(得分:1)
检查下面我用来检查的代码段。它工作正常。
你可以检查几件事:
如果仅更改进度值,则无需观看动画。
func textFieldDidBeginEditing(_ textField: UITextField) {
resetProgresses()
var view = UIProgressView()
if textField == t1 {
view = self.progressBar
view.trackTintColor = .red
view.progressTintColor = .green
}
else if textField == t2 {
view = self.progressBar2
view.trackTintColor = .green //Constant.AppColor.viewBottom
view.progressTintColor = .red//Constant.AppColor.purpleViewColor
}
if view != nil {
view.setProgress(1, animated: true)
}
}
func resetProgresses() {
self.progressBar?.setProgress(0.1, animated: true)
self.progressBar2?.setProgress(0.1, animated: true)
}