ios - swift : update of view constraints not visible

标签 ios swift uiscrollview

我确实有一个 UIScrollView,它包含几个 UIViewController。 对于 UIViewController 中的元素,我使用了 AutoLayout。 现在,如果当前设备是 iPhone 4,我想更改 View 约束的常量。 所以我覆盖了 UIViewControllersupdateViewConstraints():

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/

相关文章:

ios - 如何防止 UIWindow View 自动旋转

ios - 由于 Firebase 手机身份验证,App Store 被拒绝

ios - 如何知道水平collectionView部分是否结束减速?

swift - 对于需要返回的函数,为什么不在 for 循环内的 if-else 语句中返回就足够了?

ios - 将方法从一个类覆盖到另一个类

ios - 如何在 uistackview 中水平居中项目

iphone - 在 iOS 中播放系统声音

ios - 隐藏状态栏并增加UINavigationBar的高度

php - uploadTask 方法不起作用 URLSession Swift 3

objective-c - UIScrollView,下拉效果类似CalcBot