UIStackView animation arrSubview resizing content

Is it possible to animate an ordered view when its own content size changes?

For example, imagine that I have an organized view that contains a single UILabel attached to the edges. This label has small text. New text appears that is larger than the previous text. The internal size of the label content is now larger.

I would like to be able to animate it like this:

stackView.layoutIfNeeded() self.label.text = self.expanded ? textTwo : textOne UIView.animateWithDuration(0.3) { () -> Void in self.stackView.layoutIfNeeded() } 

The stack currently “skips” from the old content to the new, ignoring the animation block.

An alternative, of course, is to manually find out the height of the organized peep and revive this limitation. I would like to avoid this if possible.

+6
source share
1 answer

Find something that works:

 label.text = expanded ? textOne : textTwo UIView.animateWithDuration(0.4) { () -> Void in self.stackView.setNeedsLayout() self.stackView.layoutIfNeeded() } 

Does not work:

 label.text = expanded ? textOne : textTwo UIView.animateWithDuration(0.4) { () -> Void in self.stackView.layoutIfNeeded() } 

It is strange that resizing internal content does not make stackView necessary in the layout, though ...

+3
source

All Articles