我有一个包含 subview 的 UIView。 subview 通过约束更改和 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() 为我的 subview 设置动画而不是父 View ?
编辑:副作用: http://gph.is/2noI3w9
最佳答案
你可以在你的 UIView.animate 中调用它
for i in 1...cardViews.count - 1 {
let currentCard = cardViews[i]
currentCard.layoutIfNeeded()
}
代替
self.layoutIfNeeded()
关于swift - 如何在 Swift 中使用 layoutIfNeeded() 不为特定约束更改设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42768049/