我确实有一个 UIScrollView
,它包含几个 UIViewController
。
对于 UIViewController
中的元素,我使用了 AutoLayout。
现在,如果当前设备是 iPhone 4,我想更改 View 约束的常量。
所以我覆盖了 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
记录正确的新常量,更新也是不可见的。
我必须在实现中更改什么?
最佳答案
如解释here在更改 View 约束常量之前和之后,我必须集成 self.view.layoutIfNeeded()
。
关于ios - swift : update of view constraints not visible,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31372793/