【问题标题】:UIVIew size use device size in interface builder and no constraintUIVIew 大小在界面生成器中使用设备大小并且没有约束
【发布时间】:2018-02-18 19:58:05
【问题描述】:

我在界面生成器中有以下场景。

以及控制器viewDidLoad函数中的如下代码

print(String.init(format:"baseCircleView width %f height %f", baseCircleView.bounds.size.width, baseCircleView.bounds.size.height))
print(String.init(format:"userDrawingView width %f height %f", userDrawingView.bounds.size.width, userDrawingView.bounds.size.height))
print(String.init(format:"View width %f height %f", self.view.bounds.size.width, self.view.bounds.size.height))

当我启动应用程序时(在 iPhone6 模拟器上,但在情节提要中选择了“查看为:iPhone SE”),我在控制台中有以下内容:

baseCircleView 宽度 320.000000 高度 504.000000

userDrawingView 宽度 320.000000 高度 504.000000

视图宽度 375.000000 高度 667.000000

我不明白为什么我的 2 个视图从情节提要中选择的设备“View as : iPhone SE”而不是它们的超级视图推断它们的大小。

谁能帮我找出问题所在?

【问题讨论】:

    标签: ios iphone swift uiview interface-builder


    【解决方案1】:

    您应该在 viewDidLayoutSubviews 测试您的约束。

    这里是关于 UIViewController 生命周期的更多信息的博客文章: https://blog.caramba.io/ios-uiviewcontroller-lifecycle-261e3e2f6133

    【讨论】:

    • 谢谢,我找到了问题所在。我应该在 viewDidLayoutSubviews 函数而不是 viewDidLoad 中完成子视图的绘制
    猜你喜欢
    • 2014-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-10
    • 1970-01-01
    • 2011-09-26
    • 2017-05-12
    相关资源
    最近更新 更多