我有一个包含子视图的UIView。子视图使用约束更改和layoutIfNeeded()函数进行动画处理:
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
如何调用layoutIfNeeded()来动画我的子视图而不是父视图?
编辑:副作用: http://gph.is/2noI3w9
答案 0 :(得分:1)
你可以在你的UIView.animate
中调用它for i in 1...cardViews.count - 1 {
let currentCard = cardViews[i]
currentCard.layoutIfNeeded()
}
而不是
self.layoutIfNeeded()