swift - 如何在 Swift 中使用 layoutIfNeeded() 不为特定约束更改设置动画?

标签 swift animation autolayout nslayoutconstraint

我有一个包含 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/

相关文章:

ios - Xcode 7.3.1。我的事件指示器一直在旋转

ios - 在 UIPercentDrivenInteractiveTransition 中缓慢平移会导致故障

Swift: '(String) -> AnyObject?' 没有名为 'subscript' 的成员

javascript - 尝试创建连续的 on.click 事件

objective-c - 如何在 UICollectionViewLayout 和 UIViewController 之间传递数据

javascript - webkit动画播放状态: how to start/stop animation on demand with javascript

html - CSS 导航栏 slider 高亮动画?

ios - UIStackView 可以被约束吗?

ios - 设置乘数时自动布局中心 y 对齐奇怪的行为

ios - 尝试在标签上设置自动约束,但在长文本上失败