UIVIew 大小在界面生成器中使用设备大小并且没有限制
UIVIew size use device size in interface builder and no constraint
我在界面生成器中有以下场景。
以及controller的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 width 320.000000 height 504.000000
userDrawingView width 320.000000 height 504.000000
View width 375.000000 height 667.000000
我不明白为什么我的 2 个视图是从情节提要中选择的设备“View as : iPhone SE”而不是它们的父视图推断它们的大小。
谁能帮我找出问题所在?
您应该在 viewDidLayoutSubviews 测试您的约束。
这里是一个博客post,提供有关 UIViewController 生命周期的更多信息:
https://blog.caramba.io/ios-uiviewcontroller-lifecycle-261e3e2f6133
我在界面生成器中有以下场景。
以及controller的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 width 320.000000 height 504.000000
userDrawingView width 320.000000 height 504.000000
View width 375.000000 height 667.000000
我不明白为什么我的 2 个视图是从情节提要中选择的设备“View as : iPhone SE”而不是它们的父视图推断它们的大小。
谁能帮我找出问题所在?
您应该在 viewDidLayoutSubviews 测试您的约束。
这里是一个博客post,提供有关 UIViewController 生命周期的更多信息: https://blog.caramba.io/ios-uiviewcontroller-lifecycle-261e3e2f6133