I have a UIStackView
with 5 subviews. I want to be able to animate the width of these subviews by updating their intrinsicContentSize
or updating their constraints. How can I make the stackView redraw after updating the subview's layout?
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
})
I have tried various ways of trying to get the stackView to update, but nothing happens. The only way I can make it work is if I show/hide another subview inside the animation block, then the new layout is animated correctly, but I don't want to do this.
I have seen this question Animating UIStackView arrangedSubview content size change but the suggested answer does not work (nothing animates).