stackview animation - collapse of arranged subviews
That was a long time ago, but I think it helped to add self.layoutIfNeeded() before layouting superview
fileprivate func collapseWidget(){
UIView.animate(withDuration: 0.25, animations: { () -> Void in
self.background.frame.size.height = self.heightCollapsed
self.heightConstraint.constant = self.heightCollapsed
self.layoutIfNeeded()
self.superview?.layoutIfNeeded()
})
}
fileprivate func inflateWidget(){
self.separatorView.isHidden = false
UIView.animate(withDuration: 0.25, animations: { () -> Void in
self.background.frame.size.height = self.heightInflated
self.heightConstraint.constant = self.heightInflated
self.layoutIfNeeded()
self.superview?.layoutIfNeeded()
})
}
Something that could help people to get their animation working smoothly in this case, is to trigger layoutIfNeeded()
on the highest view in the hierarchy.
This is particularly helpful when your UIStackView
is embedded into an UIScrollView
. If you only trigger layoutIfNeeded
on your arrangedSubviews
or on the UIStackView
you will end up with weird glitches in your animation.
Another solution is too simply trigger layoutIfNeeded
on your UIViewController
view.
Hope this answer will help.