ios - Xcode 9 布局:有没有办法为 iPad 构建一个与 iPhone 相同内容的新故事板?
问题描述
我在为所有设备获取带有约束的布局时遇到问题,所以我的问题是,如果这是一种为 iPad 构建具有相同代码、segues 等的额外故事板的方法,那么正确获取布局会更容易。
解决方案
是的,有办法,您可以复制现有故事板并重命名它iPad_Main.storyboard
,然后您必须更正一些约束或更改适合 iPad 屏幕的值。
之后在初始化任何视图控制器之前,您必须检查设备是 iPad 还是 iPhone,并且基于此您必须使用情节提要。
let deviceIdiom = UIScreen.main.traitCollection.userInterfaceIdiom
let storyboard : UIStoryBoard!
if (deviceIdiom == .pad) {
storyboard = UIStoryboard(name: "iPad_Main", bundle: nil)
}
else {
storyboard = UIStoryboard(name: "Main", bundle: nil)
}
// Use storyboard to get desired controller using StoryboardID of UIViewController
推荐阅读
- marklogic - 用于标记逻辑的 Hadoop 连接器已从 v10 弃用
- python - 从 python open cv 到 FE angular 的实时视频流
- django - 如何获取从android设备上传的文本文件并将其存储在使用django的文件夹中?
- ruby - 如何在模块中添加类
- java - 从 openJDK 8 升级到 openJDK 11
- java - 为什么当我尝试在它自己的类中创建一个对象时它显示stackoverflowerror?
- sbt - 什么优先于 SBT_OPTS 或 .sbtopts?
- blazor - 如何在 Blazor 中同步调用 HttpClient
- azure - 如何使用或访问 Azure AD 公开的 API(MyApis)?
- r - 在 Rcpp 中,如何使用声明为 Nullable 的变量?