动画UIStackView arrangedSubview内容大小变化 [英] Animating UIStackView arrangedSubview content size change

查看:615
本文介绍了动画UIStackView arrangedSubview内容大小变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能进行动画包办子视图时,其内在含量的大小变化?

Is it possible to animate an arranged subview when its intrinsic content size changes?

例如,假设我有一个安排子视图,其中包含固定在边一个的UILabel。该标签具有文本少量。新文本进来,这比previous文本较大。标签的固有内容大小是现在更大

For example, imagine I have an arranged subview, which holds a single UILabel pinned to edges. That label has a small amount of text. New text comes in, which is larger than the previous text. The intrinsic content size of label is now larger.

我希望能够制作动画像这样:

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

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

该stackview目前跳跃从旧的内容大小到新的,忽略了动画块。

The stackview currently "jumps" from the old content size to the new one, ignoring the animation block.

当然,另一种是手动找出安排子视图的高度,和动画的约束。我想避免,如果可能的。

An alternative of course is to manually find out the height of the arranged subview, and animate that constraint. I'd like to avoid that if possible.

推荐答案

找到东西的作品:

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()
}

奇怪的是内在的内容大小的变化并不会使stackView想需要布局虽然...

Strange that changing of the intrinsic content size doesn't make the stackView want to need layout though...

这篇关于动画UIStackView arrangedSubview内容大小变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆