让 UIViewController 视图填写所有可用内容的最有效方法 space?
Most efficient way to have UIViewController view fill out all of usable space?
我有一个通用的单视图应用程序,底部有一个 UINavigationBar
toolbar
,然后 UIViewController
view
占据了 [=31] 的其余部分=].
我通常以编程方式做所有事情,所以最长的时间我一直在 loadView
中手动计算 UIViewController's
view
frame
,考虑到所有设备可能具有的组件,即新 iPhone 设备上的主页指示器高度,旧设备上的不透明状态栏。
但是,对于所有新设备,我发现这种方式效率低下,并考虑过切换到故事板或 xib。我从来没有真正使用过这些,所以我不明白它是如何工作的。例如,如果我创建一个故事板,其中 ViewController 的视图占据可用区域的整个大小,这是否适用于所有设备?旋转时会正确调整大小吗?
总的来说,我有点想知道,创建 UIViewController's
view
占据所有设备屏幕整个可用区域的应用程序的最优雅/最有效的方法是什么, 包括 phone 旋转时?
I usually do everything programmatically, so for the longest time I've been calculating the UIViewController's view frame manually in loadView
从来没有必要这样做;您可以删除该代码。导航控制器本身将为其子视图控制器的视图提供正确的框架!
您您所要做的就是为子视图控制器的视图子视图提供正确的定位。 that 是你应该做的事情,只需给它们自动布局约束,这样无论视图控制器的视图最终大小如何,它们都会正确排列。您可以在代码中或通过情节提要来做到这一点;没有区别。
In general I'm kind of wondering, what is the most elegant / efficient way to create an app where the UIViewController's view takes up the entire usable area of the screen on all devices, including when the phone rotates?
优雅高效的方法是:什么都不做。这就是已经自动发生的事情,无需您输入。
我有一个通用的单视图应用程序,底部有一个 UINavigationBar
toolbar
,然后 UIViewController
view
占据了 [=31] 的其余部分=].
我通常以编程方式做所有事情,所以最长的时间我一直在 loadView
中手动计算 UIViewController's
view
frame
,考虑到所有设备可能具有的组件,即新 iPhone 设备上的主页指示器高度,旧设备上的不透明状态栏。
但是,对于所有新设备,我发现这种方式效率低下,并考虑过切换到故事板或 xib。我从来没有真正使用过这些,所以我不明白它是如何工作的。例如,如果我创建一个故事板,其中 ViewController 的视图占据可用区域的整个大小,这是否适用于所有设备?旋转时会正确调整大小吗?
总的来说,我有点想知道,创建 UIViewController's
view
占据所有设备屏幕整个可用区域的应用程序的最优雅/最有效的方法是什么, 包括 phone 旋转时?
I usually do everything programmatically, so for the longest time I've been calculating the UIViewController's view frame manually in
loadView
从来没有必要这样做;您可以删除该代码。导航控制器本身将为其子视图控制器的视图提供正确的框架!
您您所要做的就是为子视图控制器的视图子视图提供正确的定位。 that 是你应该做的事情,只需给它们自动布局约束,这样无论视图控制器的视图最终大小如何,它们都会正确排列。您可以在代码中或通过情节提要来做到这一点;没有区别。
In general I'm kind of wondering, what is the most elegant / efficient way to create an app where the UIViewController's view takes up the entire usable area of the screen on all devices, including when the phone rotates?
优雅高效的方法是:什么都不做。这就是已经自动发生的事情,无需您输入。