2
我有UIView
两种状态:为什么layoutIfNeeded()允许在更新约束时执行动画?
我使用@IBaction
为button
它们之间的动画:
@IBAction func tapped(sender: UIButton) {
flag = !flag
UIView.animateWithDuration(1.0) {
if self.flag {
NSLayoutConstraint.activateConstraints([self.myConstraint])
} else {
NSLayoutConstraint.deactivateConstraints([self.myConstraint])
}
self.view.layoutIfNeeded() //additional line
}
}
动画工作只有当我添加额外的行:
但是当我r emove那条线,然后我的UIView
更新,但没有任何动画,它立即发生。
为什么这条线有这样的区别?它是如何工作的?