I have a UIView which contains subviews. The subviews are animated with constraints changes and layoutIfNeeded() function :
for i in 1...cardViews.count - 1 {
let currentCard = cardViews[i]
let previousCard = cardViews[i-1]
// Set new offset
currentCard.topConstraint?.constant = previousCard.contentView.frame.height + configuration.expandedOffset
}
// To animate constraints's changes
UIView.animate(withDuration: TimeInterval(duration), delay: 0, options: [.curveEaseOut], animations: {
self.layoutIfNeeded()
}, completion: nil)
But when I do this, it also animate the contraints changes of the parent. Something like this :
self.Height == containerView.Height
How can I call layoutIfNeeded() to animate my subviews but not the parent ?
EDIT : The side effect : http://gph.is/2noI3w9
parent.layoutIfNeeded
immediately before you layoutself
in the animation block. This will force the parent to layout without animations beforeself
lays out with animations – Matthew Hallattparent.layoutIfNeeded()
it animates all its subviews – Will