我想设置一个对象的动画,所以我声明了一个约束并将其添加到视图中.然后在UIView
动画中更新约束的constant
属性.为什么这个代码不移动对象?
UIView.animateWithDuration(1, animations: {
myConstraint.constant = 0
self.view.updateConstraints(myConstraint)
})
我想设置一个对象的动画,所以我声明了一个约束并将其添加到视图中.然后在UIView
动画中更新约束的constant
属性.为什么这个代码不移动对象?
UIView.animateWithDuration(1, animations: {
myConstraint.constant = 0
self.view.updateConstraints(myConstraint)
})
为了声明动画,不能重新定义约束并调用updateConstraints
.您应该更改约束的constant
,并遵循以下格式:
self.view.layoutIfNeeded()
UIView.animate(withDuration: 1) {
self.sampleConstraint.constant = 20
self.view.layoutIfNeeded()
}