Animating a hidden property on UILabels in a UIStackView calls various animations

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?

+4
ios animation uistackview animatewithduration
source share
1 answer

I have exactly the same problem. I found out that setting the Content Mode property for UILabel seems to have changed the way the UIView . In my case, I wanted to achieve animation from top to bottom. By default, the animation was a slide on the left, as well as a decrease in size. Setting content mode on Top worked for me.

Maybe this helps.

+4
source share

All Articles