UIStackView makes it easy to create nice animations using the hidden UIView property. I have two UIStackViews , each with UILabels in arrangedSubviews , and when I add a new UILabel to UIStackView , it should present it with a label animation appearing with the correct index, clicking the labels above and below.
This effect is very easy to do with UIStackViews :
descriptionLabel.hidden = true let count = descriptionStack.arrangedSubviews.count descriptionStack.insertArrangedSubview(expenseLabel.descriptionLabel, atIndex: count - 1) UIView.animateWithDuration(0.5) { descriptionLabel.hidden = false }
I want to make this effect for two different UIStackViews at the same time, but this leads to some weird behavior when it animates correctly and the other at the top of the view. Assuming the above code can be repeated for some other view and create the same animation:
descriptionLabel.hidden = true costLabel.hidden = true let count = descriptionStack.arrangedSubviews.count descriptionStack.insertArrangedSubview(expenseLabel.descriptionLabel, atIndex: count - 1) costStack.insertArrangedSubview(expenseLabel.costLabel, atIndex: count - 1) UIView.animateWithDuration(0.5) { descriptionLabel.hidden = false UIView.animateWithDuration(0.5) { costLabel.hidden = false } }
In this example, costLabel animates correctly, and descriptionLabel falls from the top of the UIStackView . In the reverse order, the order of costLabel falls, and descriptionLabel - animate correctly.
I tried variations of this animation code, for example. non-nested animations and using UIView.animateKeyframesWithDuration .
Performing this, as shown below, calls costLabel , and descriptionLabel - animate correctly:
UIView.animateWithDuration(0.5) { descriptionLabel.hidden = false } UIView.animateWithDuration(0.5) { costLabel.hidden = false }
I can not understand why the animation is always different from each other. How can I combine both labels at the same time and have an effect when they appear with the correct index by clicking on the labels above and below?