我有一个UIStackView
5个子视图。我希望能够通过更新intrinsicContentSize
或更新其约束来动画这些子视图的宽度。如何在更新子视图的布局之后使堆栈查看重绘?如何获得UIStackView来更新其布局?
UIView.animateWithDuration(0.3, animations: {
viewToResize.compressed = true //changes intrinsicContentSize
viewToResize.invalidateIntrinsicContentSize()
self.stackView.layoutIfNeeded() //makes no difference
anotherSubview.hidden = true //adding this makes everything work
})
我试过各种方式试图让stackview更新,但没有任何反应。我能做到这一点的唯一方法是,如果我在动画块中显示/隐藏另一个子视图,那么新布局的动画是正确的,但我不想这样做。
我看到这个问题 Animating UIStackView arrangedSubview content size change 但建议的答案不起作用(没有动画)。
你有没有尝试过view.updateConstraints? –
是的,在堆栈视图和子视图上,都没有任何效果。 –