Swift:视图约束的更新不可见
Swift : update of view constraints not visible
我确实有一个 UIScrollView
,里面有几个 UIViewController
。
对于 UIViewController
中的元素,我使用了 AutoLayout。
现在,如果当前设备是 iPhone 4,我想更改视图约束的常量。
所以我重写 UIViewControllers
:
的 updateViewConstraints()
override func updateViewConstraints() {
if (self.view.frame.height == 480) {
self.imageMarginLeft.constant = 40
self.imageMarginRight.constant = 40
self.textMarginTop.constant = 10
println("updateViewConstraint \(self.imageMarginRight.constant)")
}
super.updateViewConstraints()
}
但即使 println
记录了正确的新常量,更新也不可见。
我必须在实施中更改什么?
如所述,我必须在更改视图约束常量前后集成self.view.layoutIfNeeded()
。
我确实有一个 UIScrollView
,里面有几个 UIViewController
。
对于 UIViewController
中的元素,我使用了 AutoLayout。
现在,如果当前设备是 iPhone 4,我想更改视图约束的常量。
所以我重写 UIViewControllers
:
updateViewConstraints()
override func updateViewConstraints() {
if (self.view.frame.height == 480) {
self.imageMarginLeft.constant = 40
self.imageMarginRight.constant = 40
self.textMarginTop.constant = 10
println("updateViewConstraint \(self.imageMarginRight.constant)")
}
super.updateViewConstraints()
}
但即使 println
记录了正确的新常量,更新也不可见。
我必须在实施中更改什么?
如self.view.layoutIfNeeded()
。