animationUIStackView排列的子视图内容大小更改

内部内容大小变化时,是否可以对已排列的子视图进行animation制作?

例如,想象一下,我有一个排列的子视图,其中包含固定到边缘的单个UILabel。 这个标签有less量的文字。 新的文本进来,这是比以前的文字大。 标签的内在尺寸现在更大。

我想能够像这样animation:

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

堆栈视图当前从旧内容大小“跳转”到新的大小,忽略animation块。

当然,另一种方法是手动找出排列的子视图的高度,并为该约束设置animation。 如果可能,我想避免这种情况。

find可行的东西:

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

不起作用:

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

奇怪的是,改变内在的内容大小并不使堆栈视图需要布局虽然…