I have a very simple sample I created to test animating text using UIKIt...
I created 3 subviews and put them on the main view
- each subview has a UILabel in it
- the labels all have an alpha of 0 specified in their properties
- outlets for the labels are in my controller
- controller code:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let duration = TimeInterval(5)
UIView.animate(withDuration: duration, delay: 0.0, animations: {
self.testText.alpha = 1.0
})
UIView.animate(withDuration: duration, delay: duration, animations: {
self.testText2.alpha = 1.0
})
UIView.animate(withDuration: duration, delay: duration * 2, animations: {
self.testText3.alpha = 1.0
})
UIView.animate(withDuration: 3, delay: duration * 3, animations: {
self.testText.alpha = 0.0
self.testText2.alpha = 0.0
self.testText3.alpha = 0.0
})
}
Without the last animate method call, the 3 labels fade in, in sequence.
I want to fade them all out at the same time, after the last one has completely faded in.
I had expected my last animate method call to do that but, instead, the result is all of labels are displayed as alpha 1 at the beginning of the scene and then after 15 second, they all fade out.
Why does adding the last animate method call negate the effects of the first 3 animate method calls?
What should I be doing to achieve the effect I want?
I may agree with you that documentation should be imporved (not only this one). Thanks to give feedback on the answer you get.
However, what I try to explain is that concatenation does not take into account the delay you set. It just concatenate 2 animations on the same object. You may regret it, but that's it. Your code may be logical but not correct. That's why it is advised everywhere to use completion.
BTW, there is a similar situation when you deal with transform, if you've ever tried.
A bit confusing at the beginning.