Ces*_*are 37 ios nslayoutconstraint swift
我想动画一个对象,所以我声明一个约束并将其添加到视图中.然后我更新动画constant内约束的属性UIView.为什么这段代码没有移动对象?
UIView.animateWithDuration(1, animations: {
myConstraint.constant = 0
self.view.updateConstraints(myConstraint)
})
Run Code Online (Sandbox Code Playgroud)
dua*_*uan 87
为了声明动画,您无法重新定义约束和调用updateConstraints.您应该更改constant约束并遵循以下格式:
self.view.layoutIfNeeded()
UIView.animateWithDuration(1, animations: {
self.sampleConstraint.constant = 20
self.view.layoutIfNeeded()
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
47906 次 |
| 最近记录: |