如何不使用layoutifneed()在swift中变化特定的约束



i有一个包含子视图的Uiview。该子视图通过约束更改和layoutifneed()函数进行动画:

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)

但是,当我这样做时,它也会使父母的矛盾变化动画。这样的东西:

self.Height == containerView.Height

如何调用layoutifneed()来使我的子视图动画,而不是父母?

编辑:副作用:http://gph.is/2noi3w9

您可以在uiview.animate

的内部调用它
for i in 1...cardViews.count - 1 {
    let currentCard = cardViews[i]
    currentCard.layoutIfNeeded()
}

而不是

self.layoutIfNeeded()