I have set up a progressView and a textView, I want the progressView to animate its progress bar and when completed, to reset it, simultaneously changing the textView and start the animation again.
This is what I tried:
var iterator : Int = 0
fileprivate func setUpAnimation(){
switch iterator {
case 0:
interactiveShowTextView.text = quotesArray[iterator]
animateAndIterate()
case 1:
interactiveShowTextView.text = quotesArray[iterator]
animateAndIterate()
case 2:
interactiveShowTextView.text = quotesArray[iterator]
animateAndIterate()
default:
self.iterator = 0
self.setUpAnimation()
}
}
fileprivate func animateAndIterate(){
UIView.animate(withDuration: 0.0, animations: {
self.progressBar.layoutIfNeeded()
}, completion: { finished in
self.progressBar.progress = 1.0
UIView.animate(withDuration: 5, delay: 0.0, options: [.curveLinear], animations: {
self.progressBar.layoutIfNeeded()
}, completion: { finished in
print("animation completed")
self.iterator += 1
self.setUpAnimation()
})
})
}
It works fine only at the beginning when the iterator is 0, but when I iterate it to 1 the textView starts going mad continuously changing textView texts. I don't actually know why