为什么不是所有的 NSLayoutconstraints 都随动画变化,如何解决?

Why not all NSLayoutconstraints changing with animation, and how to fix it?

我在 ViewController 中有两个子视图,一个接一个(第一个的底部连接到第二个的顶部)

第一个视图正在改变它的高度动画(下面的例子),所以我预计第二个视图也会随着动画下降,但它不是..

如何制作动画?

第一个视图的动画块

func animate(){
    layoutIfNeeded()
    UIView.animateWithDuration(1){
        self.labelHeight.constant = 70 // this is constraint
        self.layoutIfNeeded()
        }
}

兄弟视图之间的约束已添加到它们的共享超级视图中,因此您应该对其调用 layoutIfNeeded()。例如:

func animate(){
    self.superview?.layoutIfNeeded()
    UIView.animateWithDuration(1){
        self.labelHeight.constant = 70 // this is constraint
        self.superview?.layoutIfNeeded()
        }
}