【问题标题】:No Constraints found in viewDidLayoutSubviews - AutoLayout在 viewDidLayoutSubviews - AutoLayout 中找不到约束
【发布时间】:2015-11-27 13:16:22
【问题描述】:

如果你庆祝它,感恩节快乐!

我在情节提要上有一个UIImageView,设置有 4 个约束。中心 x 约束有一个标识符集(通过情节提要)“imageViewTwoCenterX”。

我正在尝试使用标识符找到该约束。

问题:下面的代码为约束数组计数返回0,并且永远找不到具有标识符的约束。

我做错了吗?错误的做法?感谢所有帮助!

我使用这个代码:

override func viewDidLayoutSubviews() {
    print("Constraints Count: \(imageViewTwo.constraints.count)")
    for constraint  in imageViewTwo.constraints {
        if constraint.identifier == "imageViewTwoCenterX" {
            print("Found it!")
        }
    }

}

【问题讨论】:

    标签: ios storyboard autolayout constraints


    【解决方案1】:

    对于宽度/高度约束以外的约束,IB 将它们添加到视图的superview。所以你不会在图像视图的约束中找到它们。请尝试列出其superview 的约束。

    【讨论】:

    • 完美。非常感谢你!将在 7 分钟后接受作为答案。
    猜你喜欢
    • 2014-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-19
    • 2018-05-27
    • 2015-08-17
    • 2016-12-15
    相关资源
    最近更新 更多