Swift:视图约束的更新不可见

Ioq*_*uai 1 uiscrollview ios swift

我确实有一个UIScrollView可以容纳几个的UIViewController。对于里面的元素UIViewController我使用了自动布局。现在,如果当前设备是 iPhone 4,我想更改视图约束的常量。因此我updateViewConstraints()重写UIViewControllers

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()
} 
Run Code Online (Sandbox Code Playgroud)

但即使println记录了正确的新常量,更新也是不可见的。我在实施中需要改变什么?

Ioq*_*uai 5

正如此处所解释的,我必须self.view.layoutIfNeeded()在更改视图约束常量之前和之后进行集成。