我在 ViewController 中有两个 subview ,一个接一个(第一个的底部连接到第二个的顶部)
第一个 View 正在改变它的高度动画(下面的例子),所以我预计第二个 View 也会随着动画下降,但它不是..
如何制作动画?
第一个 View 的动画 block
func animate(){
layoutIfNeeded()
UIView.animateWithDuration(1){
self.labelHeight.constant = 70 // this is constraint
self.layoutIfNeeded()
}
}
最佳答案
兄弟 View 之间的约束被添加到它们共享的 super View 中,因此您应该对其调用 layoutIfNeeded()
。例如:
func animate(){
self.superview?.layoutIfNeeded()
UIView.animateWithDuration(1){
self.labelHeight.constant = 70 // this is constraint
self.superview?.layoutIfNeeded()
}
}
关于ios - 为什么不是所有的 NSLayoutconstraints 都随动画变化,如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37684176/